473,807 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to suppress UnicodeError exception when enabling httplib debug?

I activated httplib debug, and when trace are printed, a UnicodeError
exception is thrown. I have already set sys.stdout to use utf-8 encoding
(this removed the exception when *I* was printing unicode), but from the
stacktrace below, the encoding seems to magically have switched to 'ascii'
when httplib does the printing...

import codecs
import sys
sys.stdout = codecs.getwrite r("utf-8")(sys.__stdou t__)
....
def fetchURL( url ):
request = urllib2.Request ( url )
opener = urllib2.build_o pener( urllib2.HTTPHan dler(debuglevel =1) )
feeddata = opener.open(req uest)
data = feeddata.read()
return data.decode( 'utf-8', 'replace' )
....

Here is the traceback exceprt:

File "updater.py ", line 120, in getStoryChapter
content = fetchURL( url )
File "updater.py ", line 43, in fetchURL
feeddata = opener.open(req uest)
File "D:\python24\li b\urllib2.py", line 358, in open
response = self._open(req, data)
File "D:\python24\li b\urllib2.py", line 376, in _open
'_open', req)
File "D:\python24\li b\urllib2.py", line 337, in _call_chain
result = func(*args)
File "D:\python24\li b\urllib2.py", line 1021, in http_open
return self.do_open(ht tplib.HTTPConne ction, req)
File "D:\python24\li b\urllib2.py", line 994, in do_open
r = h.getresponse()
File "D:\python24\li b\httplib.py", line 863, in getresponse
response.begin( )
File "D:\python24\li b\httplib.py", line 365, in begin
print "header:", hdr,
File "D:\python24\li b\codecs.py", line 178, in write
data, consumed = self.encode(obj ect, self.errors)
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0x89 in position 840:
ordinal not in range(128)

Why is the print statement using the 'ascii' codec instead of utf-8? Is
there a way to ensure print always work (I'm just using it for debugging
purpose) ?
I'm using python 2.4.2.

Baptiste.
Aug 6 '06 #1
0 1587

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2884
by: Brian Beck | last post by:
Hi. I'm having some problems with code based directly on the following httplib documentation code: http://www.zvon.org/other/python/doc21/lib/httplib-examples.html I've included the code and traceback at the end of this post. The odd thing is, using DEPRECATED FUNCTIONS to perform the same function works fine!
0
4980
by: Matt | last post by:
I'm trying to get the HTML data off of a webpage. Let's say for the sake of argument it's the python homepage. I've googled around and found some examples that people said worked. Here's what I've cobbled together: #getHTML.py ############################################ import urllib import urllib2 proxy_info = {'user':'us3r',
0
2938
by: Robert | last post by:
did you solve this problem? It seems to be still present here with py2.3.5. Robert -- From: Manish Jethani <manish.j@gmx.net> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en
7
16242
by: Les Caudle | last post by:
If I have code such as: catch (WebException WebExcp) { return false; } I will get a warning CS0168: The variable 'WebExcp' is declared but never used when compiling.
2
4783
by: solar | last post by:
Is there any possibility to suppress a message box from Access ? I have a complicated but a good code that calculates the possibilities in the before update event, and if a condition is met, then it exits the sub.In short, if this condition is met, then after the exit sub I get the following message box: Runtime error 2105 you cant go to the specified recod END DEBUG If I click on End, then the code is perfect,everything I...
3
1939
by: Mark rainess | last post by:
The program displays images from a motion jpeg webcam. (Motion jpeg is a bastardization of multi-part mime.) <http://wp.netscape.com/assist/net_sites/pushpull.html> It runs perfectly for about 4 hours, then freezes. I'm stuck. How do I debug this? (Using: Python 2.4.3, wxPython 2.6.3.2, Windows 2000 and XP) There are no tracebacks, the gui continues to run,
6
7553
by: Flavio | last post by:
Hi I am havin a problem with urllib2.urlopen. I get this error when I try to pass a unicode to it. raise UnicodeError, "label too long" is this problem avoidable? no browser or programs such as wget seem to have a problem with these strings.
3
5183
by: Jon Davis | last post by:
Is there an app.config setting I can add or a System.Diagnostic.Process property I can tweak to cause someone else's CLR 2.0 console app to not show a base CLR dialog box offering to debug the app when an unhandled exception is reached? On production systems, I still get a dialog box with Debug / Close buttons. IMO, this completely violates the fundamentals of what a console app should be, but that's beside the point. I just want to...
3
11567
by: Chris Shenton | last post by:
I am setting up handlers to log DEBUG and above to a rotating file and ERROR and above to console. But if any of my code calls a logger (e.g., logging.error("foo")) before I setup my handlers, the logging system will create a default logger that *also* emits logs, which I can't seem to get rid of. Is there a way I can suppress the creation of this default logger, or remove it when I 'm setting up my handlers? Thanks. Sample code:
0
9720
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10626
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10112
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.