0

This question is repeated, but I can not find answer to problem in my context. I am trying to save Aéropostale as string in mongo DB:

name='Aéropostale'
obj=Mongo_Object()
obj.name=name
obj.save()

When I save the object, I get following error:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 2: ordinal not in range(128)

How to proceed to save the string in original format and retrieve in same format?

1 Answer 1

4

As you are using Python 2.7, you need to do a few things:

  1. Specify the file encoding, by adding a string similar to this to the top of your file:

    #coding: utf8
    
  2. Use a unicode string, as your string is not ASCII, and specify the encoding. I am using utf8 here which includes é:

    name = unicode('Aéropostale', 'utf8')
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.