python-3.x - Python http Post 错误 getaddrinfo 失败
问题描述
我正在尝试读取文件,对其进行编码并将其附加到带有 HTTPS 帖子的基本身份验证中,但出现错误:getaddrinfo failed
读取文件
filePath = "R:\SSIS\Temp\import.json"
fileBytes = open(filePath, 'r', encoding='ISO-8859-1').read
import uuid
gu = uuid.uuid4
boundary = "--" + str(gu)
设置带有边界的表单数据
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
related = MIMEMultipart('form-data', boundary) # second argument is the boundary.
file_part = MIMEApplication(
open(filePath, 'r', encoding='ISO-8859-1').read(),
)
file_part.add_header('Content-disposition', 'form-data; name="uploadedfile"')
related.attach(file_part)
body = related.as_string().split('\n\n', 1)[1]
headers = creds
做 POST
import http.client
c = http.client.HTTPSConnection("https://energytransfer.collibra.com/rest/2.0/import/json-job", 443)
r = c.request("POST", '/post', body, headers)
#get the response back
res = c.getresponse()
这是错误:
File "d:\Junk\junk.py", line 38, in <module>
r = c.request("POST", '/post', body, headers)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1253, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1299, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1248, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1008, in _send_output
self.send(msg)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 948, in send
self.connect()
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1415, in connect
super().connect()
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 919, in connect
self.sock = self._create_connection(
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\socket.py", line 822, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\socket.py", line 953, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
解决方案
推荐阅读
- java - 使用jackson序列化、反序列化复杂对象
- excel - powerquery 过滤每年的 TopN 值
- amazon-web-services - “body”处的值未能满足约束:成员不得为空
- c# - 取消令牌不适用于天蓝色队列触发功能
- javascript - Javascript 命名空间 - 从对象文字表示法 (OLN) 更新数组值
- javascript - 使用 Ajax 调用调用 api
- python - python - 使用 pdfPages / matplotlib 在 pdf 中放置几个图 - ValueError: No figure AxesImage(54,36;334.8x217.44)
- r - R GRanges:在减少 GRanges 时计算平均元数据值
- r - 使用包 dplyr 的summise
- javascript - 我的 disabled 属性不起作用 javascript