我已经用PHP编写了我自己的URL缩短程序,现在正在尝试为它开发一个python前端。我的python脚本如下:
import certifi
import urllib3
import json
manager = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())
url = input("Please enter a URL: ")
short = manager.request("GET", "https://www.get-short.net/feed.php?i=" + url)
data = short.read(decode_content=True)
print(json.loads(data))并且,当我运行它时,当我输入一个URL时,我会得到以下输出
c:\Projects>python short.py
Please enter a URL: https://docs.python.org/2/library/json.html
Traceback (most recent call last):
File "short.py", line 10, in <module>
print(json.loads(data))
File "C:\Program Files\Python36\lib\json\__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "C:\Program Files\Python36\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\Python36\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)我知道问题出在我的代码或JSON输出上,但是我必须做些什么才能让它正常工作呢
发布于 2018-01-19 00:35:22
我相信您希望使用short.data而不是short.read
short.read返回什么类型?
https://stackoverflow.com/questions/48326015
复制相似问题