python - 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,以便稍后在程序中使用。
解决方案
推荐阅读
- python - 在 matplotlib 中设置网格线上点之间的距离
- maven - Vaadin 7 部署后的问题:NoClassDefFoundError
- cmake - 从父项目否决子项目中的 cmake 宏定义?
- bash - 将日期/时间值传递给 bash 函数中的触摸命令
- javascript - 如何保存 blob 并使用 wavesurfer 播放
- python - 数据框将现有列值更改为单个特定值
- azure-cognitive-search - Azure 认知搜索 - 通过 API 创建数据源
- sql - 将 varchar 值 ' 和 f.FUNCTION_ID= CAST(' 转换为数据类型 int 时转换失败
- javascript - 如何在 JavaScript 代码中添加 HTML 按钮?
- javascript - 反应打开文件对话框