1. 程式人生 > >python學習之-- 故障記錄

python學習之-- 故障記錄

修改 文件大小 類型 nic quest rac pos iter obj

以下為我編程期間遇到的錯誤並進行記錄,起始時間2017-6-21

----------------------------------------
Exception happened during processing of request from (‘127.0.0.1‘, 48039)
Traceback (most recent call last):
File "/opt/python3/lib/python3.6/socketserver.py", line 639, in process_request_thread
self.finish_request(request, client_address)
File "/opt/python3/lib/python3.6/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/opt/python3/lib/python3.6/socketserver.py", line 696, in __init__
self.handle()
File "/root/python_study/high_ftp/core/main.py", line 84, in handle
recv_cmd = self.request.recv(1024).decode()
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd3 in position 1: invalid continuation byte
發現計算文件大小使用了len,使用方式不對。修改使用了os.path.getsize計算

Exception happened during processing of request from (‘127.0.0.1‘, 4316)
Traceback (most recent call last):
File "C:\Python36-32\lib\socketserver.py", line 639, in process_request_thread
self.finish_request(request, client_address)
File "C:\Python36-32\lib\socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Python36-32\lib\socketserver.py", line 696, in __init__
self.handle()
File "D:\51cto\python\Advance4\homework\Adv_ftp\high_ftp\core\main.py", line 106, in handle
out_result = fun(**cmd_json)
File "D:\51cto\python\Advance4\homework\Adv_ftp\high_ftp\core\main.py", line 68, in put
new_file_md5 = m.hexdegest()
AttributeError: ‘_hashlib.HASH‘ object has no attribute ‘hexdegest‘
拼寫錯誤了

Traceback (most recent call last):
File "D:/1_oldboyS14_Py/Advance4/homework/Adv_ftp/high_ftp/ftpclient/ftpclient_core.py", line 121, in <module>
ftp.interaction()
File "D:/1_oldboyS14_Py/Advance4/homework/Adv_ftp/high_ftp/ftpclient/ftpclient_core.py", line 48, in interaction
out = func(mess)
TypeError: get() takes 1 positional argument but 2 were given
原因是:發現我定義了2個同名的函數,導致出錯

Traceback (most recent call last):
File "D:/1_oldboyS14_Py/Advance4/homework/Adv_ftp/high_ftp/ftpclient/ftpclient_core.py", line 123, in <module>
ftp.interaction()
File "D:/1_oldboyS14_Py/Advance4/homework/Adv_ftp/high_ftp/ftpclient/ftpclient_core.py", line 48, in interaction
out = func(mess)
File "D:/1_oldboyS14_Py/Advance4/homework/Adv_ftp/high_ftp/ftpclient/ftpclient_core.py", line 66, in get
if recv_msg[‘id‘] == ‘200‘:
TypeError: string indices must be integers
類型錯誤

----------------------------------------
Exception happened during processing of request from (‘127.0.0.1‘, 53957)
Traceback (most recent call last):
File "D:\Python36\lib\socketserver.py", line 639, in process_request_thread
self.finish_request(request, client_address)
File "D:\Python36\lib\socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "D:\Python36\lib\socketserver.py", line 696, in __init__
self.handle()
File "D:\1_oldboyS14_Py\Advance4\homework\Adv_ftp\high_ftp\core\main.py", line 126, in handle
out_result = fun(**cmd_json)
File "D:\1_oldboyS14_Py\Advance4\homework\Adv_ftp\high_ftp\core\main.py", line 19, in get
self.request.send(kwargs.encode(‘utf-8‘))
AttributeError: ‘dict‘ object has no attribute ‘encode‘
應該發送時候轉換為字符串發送

----------------------------------------
Exception happened during processing of request from (‘127.0.0.1‘, 54134)
Traceback (most recent call last):
File "D:\Python36\lib\socketserver.py", line 639, in process_request_thread
self.finish_request(request, client_address)
File "D:\Python36\lib\socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "D:\Python36\lib\socketserver.py", line 696, in __init__
self.handle()
File "D:\1_oldboyS14_Py\Advance4\homework\Adv_ftp\high_ftp\core\main.py", line 127, in handle
out_result = fun(**cmd_json)
File "D:\1_oldboyS14_Py\Advance4\homework\Adv_ftp\high_ftp\core\main.py", line 25, in get
self.request.send(line.encode(‘utf-8‘))
AttributeError: ‘bytes‘ object has no attribute ‘encode‘
文件打開讀取就是rb模式,所以這裏不用在encode了

TypeError: argument of type ‘socket‘ is not iterable
寫錯了
應該是:if s is self.server: 寫成 if s in self.server 新手都會這樣


python學習之-- 故障記錄