I am trying to read a file, encode it and attach it to a basic authenticaion with HTTPS post, but I am getting an error: getaddrinfo failed
Reading the file
filePath = "R:\SSIS\Temp\import.json"
fileBytes = open(filePath, 'r', encoding='ISO-8859-1').read
import uuid
gu = uuid.uuid4
boundary = "--" + str(gu)
setting up the form-data with the boundary
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
doing the 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()
Here is the error:
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