ftplib.error_perm: 502 Command not implemented (python) - python

I want to get a list of folders in a ftp directory, but I'm getting the following error:
directory list of folder /myfolder
Traceback (most recent call last):
File "./run.py", line 12, in <module>
folderList = connection.nlst()
File "/usr/local/lib/python2.7/ftplib.py", line 506, in nlst
self.retrlines(cmd, files.append)
File "/usr/local/lib/python2.7/ftplib.py", line 429, in retrlines
conn = self.transfercmd(cmd)
File "/usr/local/lib/python2.7/ftplib.py", line 368, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/local/lib/python2.7/ftplib.py", line 331, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/local/lib/python2.7/ftplib.py", line 244, in sendcmd
return self.getresp()
File "/usr/local/lib/python2.7/ftplib.py", line 219, in getresp
raise error_perm, resp
ftplib.error_perm: 502 Command not implemented
And here's the sorcecode:
#!/usr/bin/python
import ftplib
connection = ftplib.FTP("10.0.99.11")
#connection.set_pasv(False)
connection.login(user='abc', passwd='1234')
rootDir = "/myfolder"
connection.cwd(rootDir)
print "directory list of folder ",rootDir
#connection.retrlines('LIST')
folderList = connection.nlst()
for folderEntry in folderList:
print folderEntry
print "end of list"
# close connection
connection.quit()
Thanks for your help and any information or idea you have.

Related

how to solving error in uploading file via ftp in python

i have this code in python2.7 for upload photos.zip file on the server via ftp.
import ftplib
session = ftplib.FTP('server.address.com','USERNAME','PASSWORD')
file = open('c:\archived\photos.zip','rb') # file to send
session.storbinary('STOR photos.zip', file) # send the file
file.close() # close file and FTP
session.quit()
but i have this error :
raceback (most recent call last):
File "a.py", line 24, in <module>
file = open('c:\archived\photos.zip','rb')
IOError: [Errno 22] invalid mode ('rb') or filename: 'c:\archived\photos.zip'
also I used this solution :
file = open(os.path.join('c:/','archived','photos.zip'),'rb')
but I get this error :
Traceback (most recent call last):
File "s.py", line 28, in <module>
session.storbinary('s.zip', file)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 479, in storbinary
conn = self.transfercmd(cmd, rest)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 378, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 341, in ntransfercmd
resp = self.sendcmd(cmd)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 251, in sendcmd
return self.getresp()
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 226, in getresp
raise error_perm, resp
ftplib.error_perm: 500 Unknown command.
Try using forward slashes :
file = open('c:/archived/photos.zip','rb') # file to send

error handling for network disconnect error

I am using pyowm to get weather update after each minutes. If I disconnect my internet or low internet what error will be occure and how can i handle this error.For try..except method..what possible exception have to use...??
my code is....
import tkinter as tk
from tkinter import *
import pyowm
from PIL import ImageTk, Image
win=tk.Tk()
#frame_for_showing_weather.
weather_frame=Frame(win,bg='black',width='300',height='300')
weather_frame.place(x=0,y=0)
weath=Label(weather_frame,font=('Agency',100),fg='white',bg='black')
weath.place(x=10,y=10)
temp1=''
owm=pyowm.OWM('my api key')
def obs():
global temp1
observation = owm.weather_at_place('Barisal,BD')
w=observation.get_weather()
temp2=w.get_temperature('celsius')
if(temp2!=temp1):
temp1=temp2['temp']
weath.config(text=str(int(temp1))+chr(176))
print('Alhamdulillah,Yeah that is worked')
weath.after(60000,obs)
obs()
win.mainloop()
please someone explain...I am new at python.
if i drop my connection this big error occure...
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "C:\Program Files (x86)\Python35-32\lib\http\client.py", line 1197, in getresponse
response.begin()
File "C:\Program Files (x86)\Python35-32\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "C:\Program Files (x86)\Python35-32\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Program Files (x86)\Python35-32\lib\socket.py", line 575, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\adapters.py", line 445, in send
timeout=timeout
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\util\retry.py", line 367, in increment
raise six.reraise(type(error), error, _stacktrace)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\packages\six.py", line 686, in reraise
raise value
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\urllib3\connectionpool.py", line 306, in _raise_timeout
raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value)
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='api.openweathermap.org', port=80): Read timed out. (read timeout=2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\commons\http_client.py", line 24, in get_json
timeout=self.timeout, verify=self.verify_ssl_certs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\requests\adapters.py", line 526, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='api.openweathermap.org', port=80): Read timed out. (read timeout=2)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "C:\Program Files (x86)\Python35-32\lib\tkinter\__init__.py", line 596, in callit
func(*args)
File "C:\Users\James Bond\Desktop\test.py", line 23, in obs
observation = owm.weather_at_place('Barisal,BD')
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\webapi25\owm25.py", line 210, in weather_at_place
_, json_data = self._wapi.cacheable_get_json(uri, params=params)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\commons\http_client.py", line 44, in cacheable_get_json
status_code, data = self.get_json(uri, params=params, headers=headers)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pyowm\commons\http_client.py", line 30, in get_json
raise api_call_error.APICallTimeoutError('API call timeouted')
pyowm.exceptions.api_call_error.APICallTimeoutError: Exception in calling OWM web API.
Reason: API call timeouted
Caused by: None
how can i handle this error...?

Pyftpsync works only without TLS

Hi I'm using pyftpsync in order to upload new images (downloaded every day) in a online store skipping the existing ones.
From the author site I'm using this code (with my personal data of course):
from ftpsync.targets import FsTarget
from ftpsync.ftp_target import FtpTarget
from ftpsync.synchronizers import UploadSynchronizer
local = FsTarget("~/temp")
user ="joe"
passwd = "secret"
remote = FtpTarget("/temp", "example.com", username=user, password=passwd)
opts= {"force": False, "delete_unmatched": True, "verbose": 3, "dry_run" : False}
s = UploadSynchronizer(local, remote, opts,tls=True)
s.run()
This work for me correctly only if I delete the tls option, otherwise I obtain this error while connecting to my server:
Traceback (most recent call last):
File "sync.py", line 25, in <module>
s.run()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/synchronizers.py", line 139, in run
res = self._sync_dir()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/synchronizers.py", line 416, in _sync_dir
remote_entries = self.remote.get_dir()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 310, in get_dir
self.ftp.retrlines("MLSD", _addline)
File "/usr/lib/python3.4/ftplib.py", line 466, in retrlines
resp = self.sendcmd('TYPE A')
File "/usr/lib/python3.4/ftplib.py", line 272, in sendcmd
return self.getresp()
File "/usr/lib/python3.4/ftplib.py", line 235, in getresp
resp = self.getmultiline()
File "/usr/lib/python3.4/ftplib.py", line 221, in getmultiline
line = self.getline()
File "/usr/lib/python3.4/ftplib.py", line 209, in getline
raise EOFError
EOFError
Could not remove lock file: Underlying socket connection gone (_ssl.c:1570)
Exception ignored in: <bound method FtpTarget.__del__ of <ftpsync.ftp_target.FtpTarget object at 0x7fe397ae7710>>
Traceback (most recent call last):
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/targets.py", line 70, in __del__
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 153, in close
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 187, in _unlock
File "/usr/lib/python3.4/ftplib.py", line 613, in delete
File "/usr/lib/python3.4/ftplib.py", line 271, in sendcmd
File "/usr/lib/python3.4/ftplib.py", line 198, in putcmd
File "/usr/lib/python3.4/ftplib.py", line 193, in putline
File "/usr/lib/python3.4/ssl.py", line 720, in sendall
File "/usr/lib/python3.4/ssl.py", line 681, in send
ssl.SSLError: Underlying socket connection gone (_ssl.c:1570)
It's obviously a problem related to the encryption, but I don't know how to fix it.

Client/Server TLS in Python

I need to create a client/server example with TLS 1.2 in Python. I spent many hours and I did not get anything...
I'm trying this example: https://github.com/titeuf87/python3-tls-example
I'm getting this error when I execute the client.py:
Exception in callback None
handle: <Handle cancelled>
Traceback (most recent call last):
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\events.py", line 125, in _run
self._callback(*self._args)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\selector_events.py", line 667, in _read_ready
self._protocol.data_received(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 486, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 200, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 633, in do_handshake
match_hostname(self.getpeercert(), self.server_hostname)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 300, in match_hostname
% (hostname, dnsnames[0]))
ssl.CertificateError: hostname '127.0.0.1' doesn't match 'server'
Traceback (most recent call last):
File "C:\Users\PC\workspace\testingpython\client.py", line 18, in <module>
loop.run_until_complete(connect())
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\base_events.py", line 342, in run_until_complete
return future.result()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py", line 274, in result
raise self._exception
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\tasks.py", line 237, in _step
result = coro.throw(exc)
File "C:\Users\PC\workspace\testingpython\client.py", line 11, in connect
reader, writer = yield from asyncio.open_connection("127.0.0.1", 1234, ssl=sslcontext)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\streams.py", line 64, in open_connection
lambda: protocol, host, port, **kwds)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\base_events.py", line 669, in create_connection
sock, protocol_factory, ssl, server_hostname)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\base_events.py", line 692, in _create_connection_transport
yield from waiter
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py", line 385, in __iter__
yield self # This tells Task to wait for completion.
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\tasks.py", line 288, in _wakeup
value = future.result()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\futures.py", line 274, in result
raise self._exception
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\events.py", line 125, in _run
self._callback(*self._args)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\selector_events.py", line 667, in _read_ready
self._protocol.data_received(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 486, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\asyncio\sslproto.py", line 200, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 633, in do_handshake
match_hostname(self.getpeercert(), self.server_hostname)
File "C:\Users\PC\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 300, in match_hostname
% (hostname, dnsnames[0]))
ssl.CertificateError: hostname '127.0.0.1' doesn't match 'server'
Does anyone know of any examples?

Can't open file error uploading file via FTPLIB and Python

I am trying to upload a file using ftplib and python. I continue getting this error and don't know why...help?
Traceback (most recent call last):
File "C:\Users\212392169\Desktop\ftp_trial.py", line 15, in <module>
ftp.storbinary("STOR samplee.bin", f)
File "C:\Python27\lib\ftplib.py", line 471, in storbinary
conn = self.transfercmd(cmd, rest)
File "C:\Python27\lib\ftplib.py", line 376, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Python27\lib\ftplib.py", line 339, in ntransfercmd
resp = self.sendcmd(cmd)
File "C:\Python27\lib\ftplib.py", line 249, in sendcmd
return self.getresp()
File "C:\Python27\lib\ftplib.py", line 224, in getresp
raise error_perm, resp
ftplib.error_perm: 550 Can't open file "samplee.bin"
Source Code:
from ftplib import FTP
ftp = FTP(host)
ftp.login(host,pw)
ftp.cwd("/dflts")
f = open('samplee.bin', 'rb')
ftp.storbinary("STOR samplee.bin", f)
f.close()
ftp.quit()
That error means that you don't have permission to upload the file.
ftp.login(host, pw)
^^^^
Is the host really what you meant?

Categories