'Python pysftp fails with "[Errno 11001] getaddrinfo failed"
I am trying to upload a file to Adobe Stock using SFTP in Python 3.8. Here are the instructions on their website: https://helpx.adobe.com/stock/how-to/upload-video-to-adobe-stock.html.
Here's my Python code:
import pysftp
pw = r'mypassword'
id = r'myid'
host = r'sftp://sftp.contributor.adobestock.com'
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection(host=host, username=id, password=pw, log="./pysftp.log", port=22, cnopts=cnopts) as sftp:
sftp.put(r'E:\myfile.mp4')
The PW and ID are just copied and pasted from Adobe Stock exactly as they provide it to me. Unfortunately, this does not work. I get the following error:
C:\Users\Joe\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py:61: UserWarning: Failed to load HostKeys from C:\Users\Joe\.ssh\known_hosts. You will need to explicitly load HostKeys (cnopts.hostkeys.load(filename)) or disableHostKey checking (cnopts.hostkeys = None).
warnings.warn(wmsg, UserWarning)
Traceback (most recent call last):
File "C:\Users\Joe\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py", line 176, in _start_transport
self._transport = paramiko.Transport((host, port))
File "C:\Users\Joe\AppData\Roaming\Python\Python38\site-packages\paramiko\transport.py", line 433, in __init__
addrinfos = socket.getaddrinfo(
File "C:\Program Files\Python\Python38\lib\socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Joe\Downloads\test adobe sftp cl.py", line 36, in <module>
with pysftp.Connection(host=host, username=id, password=pw, log="./pysftp.log", port=22, cnopts=cnopts) as sftp:
File "C:\Users\Joe\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py", line 140, in __init__
self._start_transport(host, port)
File "C:\Users\Joe\AppData\Roaming\Python\Python38\site-packages\pysftp\__init__.py", line 183, in _start_transport
raise ConnectionException(host, port)
pysftp.exceptions.ConnectionException: ('sftp://sftp.contributor.adobestock.com', 22)
What do I need to change in order to get this to work? I would like to upload to Adobe Stock using SFTP in Python but I can't quite figure out what is wrong. I am on Windows 10.
Solution 1:[1]
The host parameter of pysftp Connection constructor is:
The Hostname or IP of the remote machine.
Not an URL.
So it should be:
host = r'sftp.contributor.adobestock.com'
Additionally, do not set the cnopts.hostkeys = None, unless you do not care about security.
For the correct solution, see Verify host key with pysftp.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Martin Prikryl |
