Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:11:35+00:00 2026-05-28T22:11:35+00:00

I am using the Amazon MWS API to get the sales report for my

  • 0

I am using the Amazon MWS API to get the sales report for my store and then save that report in a table in the database. Unfortunately I am getting an encoding error when I try to encode the information as Unicode. After looking through the report (exactly as amazon sent it) I saw this string which is the location of the buyer:

‘S�o Paulo’

so I tried to encode it like so:

encodeme = 'S�o Paulo'
encodeme.encode('utf-8)

but got the following error

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xef in position 1: ordinal not in range(128)

The whole reason why I am trying to encode it is because as soon as Django sees the � character it throws a warning and cuts off the string, meaning that the location is saved as S instead of

São Paulo

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:11:35+00:00Added an answer on May 28, 2026 at 10:11 pm

    It looks like you are having some kind of encoding problem.

    First, you should be very certain what encoding Amazon is using in the report body they send you. Is it UTF-8? Is it ISO 8859-1? Something else?

    Unfortunately the Amazon MWS Reports API documentation, especially their API Reference, is not very forthcoming about what encoding they use. They only encoding I see them mention is UTF-8, so that should be your first guess. The GetReport API documentation (p.36-37) describes the response element Report as being type xs:string, but I don’t see where they define that data type. Maybe they mean XML Schema’s string datatype.

    So, I suggest you save the byte sequence you are receiving as your report body from Amazon in a file, with zero transformations. Be aware that your code which calls AWS might be modifying the report body string inadvertently. Examine the non-ASCII bytes in that file with a binary editor. Is the “São” of “São” stored as S\xC3\xA3o, indicating UTF-8 encoding? Or is it stored as S\xE3o, indicating ISO 8859-1 encoding?

    I’m guessing that you receive your report as a flat file. The Amazon AWS documentation says that you can request reports be delivered to you as XML. This would have the advantage of giving you a reply with an explicit encoding declaration.

    Once you know the encoding of the report body, you now need to handle it properly. You imply that you are using the Django framework and Python language code to receive the report from Amazon AWS.

    One thing to get very clear (as Skirmantas also explains):

    • Unicode strings hold characters. Byte strings hold bytes (octets).
    • Encoding converts a Unicode string into a byte string.
    • Decoding converts a byte string into a Unicode string.

    The string you get from Amazon AWS is a byte string. You need to decode it to get a Unicode string. But your code fragment, encodeme = 'São Paulo', gives you a byte string. encodeme.encode('utf-8) performs an encode() on the byte string, which isn’t what you want. (The missing closing quote on 'utf-8 doesn’t help.)

    Try this example code:

    >>> reportbody = 'S\xc3\xa3o Paulo'   # UTF-8 encoded byte string
    >>> reportbody.decode('utf-8')        # returns a Unicode string, u'...'
    u'S\xe3o Paulo'
    

    You might find some background reading helpful. I agree with Hoxieboy that you should take the time to read Python’s Unicode HOWTO. Also check out the top answers to What do I need to know about Unicode?.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an application that utilizes Amazon's MWS API written mostly in PHP.
Using Amazon's own client libraries (or alternatives ), you can get listings of available
I am using Amazon S3 to back up my Rails app's mysql database. And
I try to use amazon API using PHP. If I use print_r($parsed_xml->Items->Item->ItemAttributes) it show
im using the C# Library for Batch Data Exchange Feeds from https://mws.amazon.com/doc/en_US/bde/feeds/v20090901/cSharp.html I want
For the API script of followcost.com. It is given that for using the follow
I am trying to force files to download from Amazon S3 using the GET
I'm using rJava to speak to the Amazon Web Services Java API from inside
I'm using Paperclip 2.3.5 within a Rails app to store PDF documents on Amazon
I am using amazon S3 service with PHP by using this API https://github.com/tpyo/amazon-s3-php-class I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.