473,545 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why not in python 2.4.3

hi
I made the upgrade to python 2.4.3 from 2.4.2.
I want to take from google news some atom feeds with a funtion like
this
import urllib2
def takefeed(url):
request=urllib2 .Request(url)
request.add_hea der('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5;
Windows NT')
opener = urllib2.build_o pener()
data=opener.ope n(request).read ()
return data
url='http://news.google.it/?output=rss'
d=takefeed(url)
This woks well with python 2.3.5 but does not work with 2.4.3.
Why?
Thanks

May 28 '06 #1
10 2447

Rocco wrote:
hi
I made the upgrade to python 2.4.3 from 2.4.2.
I want to take from google news some atom feeds with a funtion like
this
import urllib2
def takefeed(url):
request=urllib2 .Request(url)
request.add_hea der('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5;
Windows NT')
opener = urllib2.build_o pener()
data=opener.ope n(request).read ()
return data
url='http://news.google.it/?output=rss'
d=takefeed(url)
This woks well with python 2.3.5 but does not work with 2.4.3.
Why?


Define "woks [sic] well". It works fine for me on 2.4.3 (and by "works
fine" I mean it ran without an exception and it returned what appeared
to be RSS data). If you would give us an exception trace it would help
a lot.

Maybe Google's server (or your ISP's) was down. That happens
sometimes.

Carl

May 28 '06 #2
Rocco:
but does not work with 2.4.3.


Define "does not work".

--
René Pijlman
May 28 '06 #3
This is the problem when I run the function
this is the result from 2.3.5
print rss <?xml version="1.0" encoding="UTF-8"?><feed version="0.3" xml:lang="it"
xmlns="http://purl.org/atom/ns#"><generator >NFE/1.0</generator><titl e>Google
News Italia</title><link rel="alternate" type="text/html"
href="http://news.google.it/"/><tagline>Googl e News
Italia</tagline><author ><name>Google
Inc.</name><email>ne* **********@goog le.com</email></author><copyrig ht>&amp;copy;20 06
Google</copyright><modi fied>2006-05-28T19:09:13+00: 00</modified>
<!-- A couple notes:
* add an "output=ato m" param to get Atom
* section pages have a "topic=?" param;
use "topic=h" for a Top Stories section.
--><entry><title> Benedetto XVI: Wojtyla santo subito - LibertÃ
</title><link rel="alternate" type="text/html"
href="http://www.liberta.it/default.asp?IDG =605282024"/><id>tag:news.g oogle.com,2005: cluster=41b535f b</id><summary>Pri ma
pagina</summary><issued >2006-05-28T11:05:00+00: 00</issued><modifie d>2006-05-28T11:05:00+00: 00</modified><conte nt
type="text/html" mode="escaped"> &lt;br&gt;&lt;t able border=0 align=
cellpadding=5 cellspacing=0&g t;&lt;tr&gt;&lt ;td width=80 align=center
valign=top&gt;& lt;a .....
import sys
sys.getdefaulte ncoding() 'ascii' this is the result with 2.4.3 print rss ヒ rss '\x1f\x8b\x08\x 00\x00\x00\x00\ x00\x02\xff\xe5 }Ks\xe3F\xb6\xe 6\xfeF\xdc\xff\ x90\xd77\xba\xc 3\x9e\x10D\xbc\ x01\xcaU\xee\xa 1\x9eM[\xa2\xd4$\xabl\ xf7\x86\x93\x04 \x93Tv\x81H\x1a \x0fV\xa9V\xfe\ x0f3\x9b\x8e\x9 8\x89\xb8\xcb\x 1b\xd1\xb3\x9a\ xddD\xef\xec\x7 f\xe2_2\xe7$\x0 0\x8a/\x11|\x93\xd6\x b4\xa3U"\x04\x0 2\x99\xe7d\x9e< \xdfy\xbe\xf9\x d3\xa7\xbeO\x86 ,\x8c\xb8\x08\x de~\xa1\x9d\xaa _\x10\x16x\xa2\ xc3\x83\xde\xdb/\xde5\xaf\x15\x f7\x8b?}\xf3&\x 8c\xa2\xe7\x9bt \xb8\xe9\x9b7\x de#\r\x02\xe6\x 7f\xf3\xa6\xc7\ x02\x16\xd2X\x8 4\xdf\xd4\xae\x afJ\xf0\x847\xa 5\xe7Kob\x1e\xf b\xec\x9b\x1b!z >#5\xf61"\xd5\x 98\xfa\x9c\xbe) \xa5\x7fy\xe3\x f3\xe0\xc37\x8f q<8+\x95\x02\xf 8\xfbiO\xde{\xc a\xe3\xd2\x9b\x 92\xfc\xe3\x9b\ x0e\x8b\xbc\x90 \x0fbx\xfb\xdc\ '\x8d\xff\xfd\x 8dO\x83^B{\xec\ x1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\x83A(\xba"\xe 8\xf0>\x0bb\x0e \x04\xea\xb0O\x a74\x
import sys
sys.getdefaulte ncoding() 'latin_1'

No exception trace
Thanks again

May 28 '06 #4
Rocco wrote:
import sys
sys.getdefaulte ncoding()

'latin_1'


Don't change default encoding. It should be always ascii.

May 29 '06 #5
Also with ascii the function does not work.

May 29 '06 #6
Rocco wrote:
Also with ascii the function does not work.


Well, at least you fixed misconfiguratio n ;)

Googling for 1F8B (that's two first bytes from your strange python 2.4
result) gives a hint: it's a beginning of gzip stream. Maybe urllib2 in
python 2.4 reports to the server that it supports compressed data but
doesn't decompress it when receives the reply?

May 29 '06 #7
Thanks Serge.
It's a gzip string.
So the code is
import urllib2
def takefeed(url): request=urllib2 .Request(url)
request.add_hea der('User-Agent', 'Mozilla/4.0 (compatible; MSIE
5.5;Windows NT')
opener = urllib2.build_o pener()
data=opener.ope n(request).read ()
return data
url='http://news.google.it/?output=rss'
d=takefeed(url)
from StringIO import StringIO
zipdata=StringI O(d)
import gzip
gz=gzip.GzipFil e(fileobj=zipda ta)
rss=gz.read()
len(rss) 102529 print rss[0:100] <?xml version="1.0" encoding="UTF-8"?><rss
version="2.0">< channel><genera tor>NFE/1.0</generator><tit


May 29 '06 #8
On 29/05/2006 10:47 PM, Serge Orlov wrote:
Rocco wrote:
Also with ascii the function does not work.
Well, at least you fixed misconfiguratio n ;)

Googling for 1F8B (that's two first bytes from your strange python 2.4
result) gives a hint: it's a beginning of gzip stream.


Well done!
Maybe urllib2 in
python 2.4 reports to the server that it supports compressed data but
doesn't decompress it when receives the reply?


Something funny is happening here. Others reported it working with 2.4.3
and Rocco's original code as posted in this thread -- which works for me
on 2.4.2, Windows XP.

There was one suss thing about Rocco's problem description:
First message ended with d=takefeed(url)
But next message said print rss
Is rss == d?

Cheers,
John
May 30 '06 #9
On 30/05/2006 12:44 AM, Rocco wrote:
Thanks Serge.
It's a gzip string.


Look, Ma, no gzip!!!

C:\junk>rocco_r ss.py
'<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0">< channel><genera tor>NF
E/1.0</generator><tit'

C:\junk>type rocco_rss.py
import urllib2
def takefeed(url):
request=urllib2 .Request(url)
request.add_hea der('User-Agent', 'Mozilla/4.0 (compatible; MSIE
5.5; Win
dows NT')
opener = urllib2.build_o pener()
data=opener.ope n(request).read ()
return data
url='http://news.google.it/?output=rss'
d=takefeed(url)
print repr(d[:100])
May 30 '06 #10

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

Similar topics

0
7401
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...
0
7656
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. ...
0
7808
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...
1
7423
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...
0
7757
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...
0
5972
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...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.