0

I am getting a plaintext from a webservice into an object p and I want to store it on a .txtfile using Python.

I do something like:

with open("output","w") as t2:
    t2.write(p.content)

but the following encoding issue arises:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 10: ordinal not in range(128)

I am on Ubuntu and PycharmIDE. How can I overcome this problem?

2

1 Answer 1

3

You can try using

p2.content.encode('utf-8')

or

p2.content.encode('ascii', 'ignore')

Sign up to request clarification or add additional context in comments.

2 Comments

I think it worked and will accept your answer soon
What is the the output of print p.content and print type(p.content)?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.