首页 > 解决方案 > JSONDecodeError:期望值:第 1 行第 1 列(字符 0)尝试通过用户 IP 查找位置

问题描述

import json
import geocoder
g = geocoder.freegeoip('')
g.json

本质上,这只是在您运行它时使用您的 ip 获取您的纬度/经度坐标。

当我尝试时,我得到了这个:

---------------------------------------------------------------------------

JSONDecodeError                           Traceback (most recent call last)

<ipython-input-36-09a3ee1f4b06> in <module>()
----> 1 g = geocoder.freegeoip('')
      2 g.json

<8 frames>

/usr/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我对这意味着什么或为什么会遇到这个问题一无所知。

此片段的最终目标是返回用户的 ip,以便稍后在程序中使用。

标签: pythonjson

解决方案


推荐阅读