3

I tried to fetch some info from a website but got this instead .

here is the code..

import requests
r = requests.get("http://erp.college_name.edu/").text
print(r)

and here is the error..

Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Users\User\AppData\Local\Programs\Python\Python35-
  32\lib\encodings\cp437.py", line 19, in encode
     return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\xa9' in 
   position 7435: character maps to <undefined>

i am trying to login to my id using requests.
any help?

4
  • Your PYTHONIOENCODING is likely not set to UTF-8. Please verify this by trying to print(u'♠'). If this throws the same exception, consult this answer Commented Mar 15, 2017 at 15:29
  • @talkdirty im get6ting this >>> print(u'♠') ♠ it means there isnt any problem with my console, then what is it? Commented Mar 15, 2017 at 15:31
  • and what does it have to do with web-scraping Commented Mar 15, 2017 at 15:35
  • Nothing with web scraping directly, but my guess was that python had trouble displaying the content in the terminal. Since it works to you though, i was wrong here. what do you get for r.encoding? Commented Mar 17, 2017 at 9:29

1 Answer 1

4

You can encode the text with 'utf-8', then the string can be print out correctly.

import requests
r = requests.get("http://erp.college_name.edu/").text

print(r.encode('utf-8'))
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.