0

我目前正在研究一种通过http客户端更新一些数据的方法,所以我正在运行教程基础知识并且遇到一个错误,显然正在使用的url太长,

```
import http.client

url = 'kube...ordercapacities' #(It's 109 characters long)

conn = http.client.HTTPConnection(url)
conn.request("GET", "/")
r1 = conn.getresponse()
print(r1.status, r1.reason)
```

错误发生在 conn.request 行,错误是:

>Traceback (most recent call last):
  File "C:/Users/rs764y/PycharmProjects/PythonTest/Testing.py", line 31, in <module>
    conn.request("GET", "/")
  File "C:\Program Files\Python\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files\Python\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files\Python\lib\http\client.py", line 1010, in _send_output
    self.send(msg)
  File "C:\Program Files\Python\lib\http\client.py", line 950, in send
    self.connect()
  File "C:\Program Files\Python\lib\http\client.py", line 921, in connect
    self.sock = self._create_connection(
  File "C:\Program Files\Python\lib\socket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Program Files\Python\lib\socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label too long)
>

有什么解决方法吗?还是我应该使用不同的模块?最终目标是用新值/数据覆盖该 URL 上的当前内容

4

0 回答 0