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?

Yash Mehrotra
  • 3,032
  • 1
  • 21
  • 24
Leonardo
  • 337
  • 2
  • 5
  • 12

1 Answers1

3

You can try using

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

or

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

Yash Mehrotra
  • 3,032
  • 1
  • 21
  • 24