Problem: urllib.quote (xxx)
error after running * * * keyerror: u '\ uxx'
reason: look at XXX
type: & lt; type 'unicode'>
, and params
in urlib.quote (params)
is a string. You can only guess that the encoding of the string does not meet the requirements, so the code XXX
solution: urlib.quote (XXX. Encode ("UTF-8")
or urlib.quote (STR (xxx))
Examples are as follows:
>>> import urllib
>>> xxx = u'[{"test":"Test"}]'
>>> urllib.quote(xxx)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1298, in quote
return ''.join(map(quoter, s))
KeyError: u'\u6d4b'
>>> type(xxx)
<type 'unicode'>
>>> urllib.quote(xxx.encode("utf-8"))
'%5B%7B%22test%22%3A%22%E6%B5%8B%E8%AF%95%22%7D%5D'
>>> urllib.quote(str(xxx))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-11: ordinal not in range(128)
>>> import sys
>>> sys.setdefaultencoding('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setdefaultencoding'
>>> reload(sys)
<module 'sys' (built-in)>
>>> sys.setdefaultencoding('utf-8')
>>> urllib.quote(str(xxx))
'%5B%7B%22test%22%3A%22%E6%B5%8B%E8%AF%95%22%7D%5D'
Read More:
- Python Pandas Error: KeyError: 0 [How to Solve]
- How to Fix keyerror in Python dictionary lookup
- [Solved] ufunc ‘add‘ did not contain a loop with signature matching types (dtype(‘<U32‘), dtype(‘<U32‘))
- KeyError: b ‘TEST’ problem in python3 conversion from csn-rcnn code
- [Solved]AttributeError: module ‘urllib’ has no attribute ‘quote’
- [Solved] raise KeyError(key) from err KeyError: ‘Dates‘
- numpy.concatenate() 253rd; 38169Keyerror: 0 [How to Solve]
- Error in sitecustomize set PYTHONVERBOSE for traceback KeyError: ‘PYTHONPATH’
- Flash cli encountered a keyerror “migrate” [How to Solve]
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- [Solved] PyTorch Lightning Error: KeyError: ‘hidden_states‘
- odoo Error: KeyError:‘ir.http‘ [How to Solve]
- How to Solve Automatic error keyerror:***‘
- [How to Fix] TypeError: Cannot cast array data from dtype(‘float64‘) to dtype(‘<U32‘)….
- [Solved] KeyError: ‘Transformer/encoderblock_0/MultiHeadDotProductAttention_1/query\\kernel is
- [Solved] flash initializate database error: Keyerror: ‘migrate’
- [Solved] D455 Depth Camera Error: keyerror: ‘frame_ device_ t‘
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- [Solved] cv2.error: (-215:Assertion failed) encoder->isFormatSupported(CV_8U) in function ‘imwrite_‘