在執行imgr.py時,選擇要識別的圖片後,產生以下錯誤,應該如何修改
self._output(request.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode characters
PS G:\Item\28AIpicture\imagerecognition> python imgr.py
Traceback (most recent call last):
File "imgr.py", line 30, in <module>
sys.setdefaultencoding( "utf-8" )
AttributeError: module 'sys' has no attribute 'setdefaultencoding'
PS G:\Item\28AIpicture\imagerecognition> python imgr.py
Traceback (most recent call last):
File "imgr.py", line 184, in openfile
self.typeTp()
File "imgr.py", line 191, in typeTp
self.get_bankcard(self.get_token())
File "imgr.py", line 244, in get_token
response = urllib.request.urlopen(request)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\urllib\request.py", line 543, in _open
'_open', req)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\urllib\request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\urllib\request.py", line 1317, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 1240, in _send_request
self.putrequest(method, url, **skips)
File "C:\Users\064105\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 1107, in putrequest
self._output(request.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 61-65: ordinal not in range(128)