我正在尝试从此网站检索JSON数据: www.themoviedb.org 我只能使用http.client和json作为库。 我有一个有效的API密钥,我不想在此问题中透露。
url = "https://api.themoviedb.org/3/movie/550?api_key=xxxx"
conn = http.client.HTTPConnection(url,port=80)
## things work well until i call request
conn.request("GET","/")
错误:
for res in _socket.getaddrinfo(host, port, family, type, proto, flags)
: socket.gaierror:[Errno 11001] getaddrinfo失败
答案 0 :(得分:1)
当称为https站点时,请改用HTTPSConnection。另外,您还会错误地解析网址。这是我未经测试的示例。告诉我它是否失败。
import http.client
conn = http.client.HTTPSConnection("api.themoviedb.org")
conn.request("GET", "/3/movie/550?api_key=xxxx")
r1 = conn.getresponse()
print(r1.status, r1.reason)
if r1.status == 200:
data1 = r1.read()