【发布时间】:2021-01-21 11:39:07
【问题描述】:
我正在运行以下代码,它在 python 2.7 中运行良好,但在 python 3.7 或 3.9 编译器中抛出错误。
import requests
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
username = "geeks_for_geeks"
user_info = requests.get('https://instagram.com/%s/?__a=1'%username, headers = headers)
print (user_info.json())
python中的错误如下:
Traceback(最近一次调用最后一次): 文件“”,第 13 行,在 json中的文件“/usr/lib/python3/dist-packages/requests/models.py”,第897行
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
【问题讨论】:
-
你能发布完整的回溯吗?
-
如果您想提出更多请求,请查看instagrams官方api:developers.facebook.com/docs/instagram-basic-display-api
-
请显示完整的错误回溯,而不仅仅是一行。
-
我已经更新了完整的代码
标签: python python-3.7