gpt4 book ai didi

python - 使用 python http.client 访问 korbit api

转载 作者:太空宇宙 更新时间:2023-11-03 17:55:20 24 4
gpt4 key购买 nike

我一直在尝试访问以下API: https://api.korbit.co.kr/v1/ticker/detailed

我知道我可以使用任何互联网浏览器访问此内容,但我很难将它实现到 python 上。

我使用了以下代码:

import http.client

conn = http.client.HTTPSConnection("https://api.korbit.co.kr", 443)
conn.request("GET", "/v1/ticker/detailed")
response = conn.getresponse()
data = response.read()
conn.close()

回溯:

Traceback (most recent call last):
File "C:/Users/K/PycharmProjects/nektie/test.py", line 4, in <module>
conn.request("GET", "/v1/ticker/detailed")
File "C:\Python34\lib\http\client.py", line 1090, in request
self._send_request(method, url, body, headers)
File "C:\Python34\lib\http\client.py", line 1128, in _send_request
self.endheaders(body)
File "C:\Python34\lib\http\client.py", line 1086, in endheaders
self._send_output(message_body)
File "C:\Python34\lib\http\client.py", line 924, in _send_output
self.send(msg)
File "C:\Python34\lib\http\client.py", line 859, in send
self.connect()
File "C:\Python34\lib\http\client.py", line 1221, in connect
super().connect()
File "C:\Python34\lib\http\client.py", line 836, in connect
self.timeout, self.source_address)
File "C:\Python34\lib\socket.py", line 491, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Python34\lib\socket.py", line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

最佳答案

http.client.HTTPSConnection接受主机名,而不是 URL。

conn = http.client.HTTPSConnection("api.korbit.co.kr", 443)

顺便说一句,我建议使用像 python-requests 这样的库:

import requests

r = requests.get('https://api.korbit.co.kr/v1/ticker/detailed')
data = r.json()

关于python - 使用 python http.client 访问 korbit api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28528316/

24 4 0
文章推荐: ruby-on-rails - 无法在 ruby​​ 中转储匿名类类
文章推荐: c# - 如何指定 C# 泛型类型必须支持 Parse(string)?
文章推荐: python - 如何提取下的所有源代码并导出为html?