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

  • Home
  • SEARCH
  • 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 7032231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:54:28+00:00 2026-05-28T00:54:28+00:00

I am trying to download page_source to a file. However, every time I get

  • 0

I am trying to download page_source to a file. However, every time I get a:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 (or something else) in 
position 8304: ordinal not in range(128)

I’ve tried using value.encode('utf-8'), but it seems every time it throws the same exception (in addition to manually trying to replace every non-ascii character). Is there a way to ‘pre-process’ the html to put it into a ‘write-able’ format?

  • 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-28T00:54:29+00:00Added an answer on May 28, 2026 at 12:54 am

    There are third party libraries such as BeautifulSoup and lxml that can deal with encoding issues automatically. But here’s a crude example using just urlllib2:

    First download some webpage containing non-ascii characters:

    >>> import urllib2
    >>> response = urllib2.urlopen('http://www.ltg.ed.ac.uk/~richard/unicode-sample.html')
    >>> data = response.read()
    

    Now have a look for the “charset” at the top of the page:

    >>> data[:200]
    '<html>\n<head>\n<title>Unicode 2.0 test page</title>\n<meta
    content="text/html; charset=UTF-8" http-equiv="Content-type"/>\n
    </head>\n<body>\n<p>This page contains characters from each of the
    Unicode\ncharact'
    

    If there was no obvious charset, “UTF-8” is usually a good guess, anyway.

    Finally, convert the webpage to unicode text:

    >>> text = data.decode('utf-8')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to download a CSV file using HttpResponse to make sure that
I'm trying to download http://www.downway1.com/dota/eng/DotA%20Allstars%20v6.67.w3x this file. But it's not able to download. It's
I am trying to download libstdc++-v3/python to enable pretty printing of stl containers. However,
I'm trying to download an html file with curl in bash. Like this site:
I am trying to figure out the way to download an image file for
I'm trying to create a file download page. This page when requested should prompt
I'm trying to get the download link of wordpress' plugins via bash script directly
Im trying to download and synchronize imap email but when I download certain messages
Im trying to download share data from a stock exchange using python. The problem
I'm trying to download images (.jpg) from web folder using wget. I want to

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.