D
D
danis_20142017-02-05 19:06:49
Python
danis_2014, 2017-02-05 19:06:49

Why does the problem get out when the script is run through the console, but when run through PyCharm everything is fine?

There is this code:

import paramiko

def postData():
    host = '78.24.218.24'
    username = 'root'
    password = 'password'
    transport = paramiko.Transport((host, 22))
    transport.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(transport)
    sftp.put(r'data.txt', r'/root/vk-ali/data.txt')
    sftp.put(r'album1.txt', r'/root/vk-ali/album1.txt')
    sftp.put(r'posts1.txt', r'/root/vk-ali/posts1.txt')  # на этом моменте ошибка
    sftp.put(r'posts2.txt', r'/root/vk-ali/posts2.txt')
    sftp.put(r'album2.txt', r'/root/vk-ali/album2.txt')
    sftp.close()
    transport.close()

# Traceback (most recent call last):
#  File "C:\Users\danis\AppData\Local\Programs\Python\Python36-32\Lib\vk_ali\desktop\server.py", line 41, in #<module>
#   postData()
#  File "C:\Users\danis\AppData\Local\Programs\Python\Python36-32\Lib\vk_ali\desktop\server.py", line 14, in # postData
#   sftp.put('posts1.txt', r'/root/vk-ali/posts1.txt')
# File "C:\Users\danis\AppData\Local\Programs\Python\Python36-32\lib\site-
#   packages\paramiko\sftp_client.py", line 674, in put
#    file_size = os.stat(localpath).st_size
# FileNotFoundError: [WinError 2] Не удается найти указанный файл: 'posts1.txt'

But the main thing is that the error occurs only when I run the script through the console. That is, when running with PyCharm, no errors. Any ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Error 502, 2017-02-05
@danis_2014

From my own experience I will say: such problems often arise if you have 2 versions of python installed. at the same time, one is launched in PyCharm, and another one is launched in the console. Also, judging by the errors, in your case, the libraries necessary for your script are installed under one version, but they are not in the other version, so it screams. try again to run in the console, writing "python3" instead of "python".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question