0

我正在尝试从以下网站检索 JSON 数据:www.themoviedb.org 我只能将 http.client 和 json 用作库。我有一个有效的 API KEY,我不想在这个问题中透露。

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 失败

4

1 回答 1

6

当调用 https 站点时,请改用 HTTPSConnection。您也错误地解析了 url。这是我未经测试的示例。告诉我它是否失败。

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()
于 2019-01-13T03:03:31.573 回答