urllib2 redirect error

2014-09-01 Thread Sumit Ray
Hi,

I've tried various versions but continue to get the following error:
-- 
https://mail.python.org/mailman/listinfo/python-list


urllib2 redirect error

2014-09-01 Thread Sumit Ray
Hi,

 I've tried versions of the following but continue to get errors:

- snip -
url = 'https://www.usps.com/send/official-abbreviations.htm'
request = urllib2.build_opener(urllib2.HTTPRedirectHandler).open(url)
- snip -

Generates an exception:
urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect
error that would lead to an infinite loop.
The last 30x error message was:
Moved Permanently


The following using the requests library hangs:
- snip -
response = requests.get(url)
- snip -

I'm fresh out of ideas and any suggestions you may have would be greatly
appreciated.

Thanks in advance,
Sumit
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: urllib2 redirect error

2014-09-06 Thread Sumit Ray
Steven,

Thank you! User advice was on point.

Sumit


On Tue, Sep 2, 2014 at 11:29 PM, dieter  wrote:

> Steven D'Aprano  writes:
> > ...
> > I'm not an expert, but that sounds like a fault at the server end. I just
> > tried it in Chrome, and it worked, and then with wget, and I get the same
> > sort of error:
> > ...
> > Sounds like if the server doesn't recognise the browser, it gets
> > confused and ends up in a redirect loop.
> >
> > You could try setting the user-agent and see if that helps:
>
> Excellent analysis and advice.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list