python - Error in encoding string -


this might simple problem not able solve it.

in python console :

request.request.data.get('comment') 

i {u'price': u'21', u'unit': u'30\xd730', u'name': u'test', u'comments': u'check'}

the value of comment :

            "comments" : "check",             "name" : "test",             "price" : "21",             "unit" : "30×30"(multiplication sign x) 

how can solve such request.request.data.get('comment') {u'price': u'21', u'unit': u'30x30', u'name': u'test', u'comments': u'check'}?

i tried using:

request.request.data.get('comment').get('unit').encode('utf-8') 

but returns '30\xc3\x9730'

i want convert /xd ascii.

it seems feature (bug?) in methods

dict.__repr__()  

and/or

dict.__str__()  

of python 2.7.x. ok. can check by

print a[u'unit'] 

which prints

30x30 

p.s. no problems in python 3.5.2...

see below interactive session of python 2.7 in unicode pycharm console:

python 2.7.12 (v2.7.12:d33e0cf91556, jun 27 2016, 15:19:22) [msc v.1500 32 bit (intel)] on win32 >>> a=u'\xd7' >>> u'\xd7' >>> print × 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -