Http Error 302 Urllib2
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site python http error 302: the http server returned a redirect error that would lead to an infinite loop About Us Learn more about Stack Overflow the company Business Learn more about
The Last 30x Error Message Was: Found
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss urllib vs urllib2 Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Handling rss redirects
Urllib Cookies
with Python/urllib2 up vote 13 down vote favorite 5 Calling urrlib2.urlopen on a link to an article fetched from an RSS feed leads to the following error: urllib2.HTTPError: HTTP Error 301: The HTTP server returned a redirect error tha t would lead to an infinite loop. The last 30x error message was: Moved Permanently According to the documentation, urllib2 supports redirects. On Java the problem cookielib python 3 was solved by just calling HttpURLConnection.setFollowRedirects(true); How can I solve it with Python? UPDATE The link I'm having problems with: http://feeds.nytimes.com/click.phdo?i=8cd5af579b320b0bfd695ddcc344d96c python redirect urllib2 share|improve this question edited Mar 29 '12 at 13:14 asked Mar 29 '12 at 13:09 Alex 6,1441154100 Redirects are on by default. Read the error message again. To determine if this is an error in the std-lib you would have to supply the URL, for checking. Note, that also the server could return different stuff based on the sent User-Agent. –sleeplessnerd Mar 29 '12 at 13:14 I've added the url. Looks like there are more than 5 redirects. But Java copes with them without any extra stuff like user agent. –Alex Mar 29 '12 at 13:15 Possible duplicate of Python urllib2.urlopen returning 302 error even though page exists –Krastanov Mar 16 at 23:46 add a comment| 2 Answers 2 active oldest votes up vote 23 down vote accepted Turns out you need to enable Cookies. The page redirects to itself after setting a cookie first. Because urllib2 does not handle cookies by default you have to do it yourself. import urllib2 import urlli
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more
Python Requests
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Python Cookiejar
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How do I set cookies using Python urlopen? up vote 3 down vote favorite 5 I am trying to fetch an html site using Python urlopen. I am getting http://stackoverflow.com/questions/9926023/handling-rss-redirects-with-python-urllib2 this error: HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop The code: from urllib2 import Request request = Request(url) response = urlopen(request) I understand that the server redirects to another URL and that it is looking for a cookie. How do I set the cookie it is looking for so I can read the html? python cookies redirect urlopen http-error share|improve this question edited Feb 2 '12 http://stackoverflow.com/questions/9113652/how-do-i-set-cookies-using-python-urlopen at 15:43 DzinX 23.2k74371 asked Feb 2 '12 at 14:03 yossi 5,553145190 2 You have a web page that redirects to another web page which redirects to the first one (loop). –Mariusz Jamro Feb 2 '12 at 14:06 yeah i know that, i am looking for a way to get around this –yossi Feb 2 '12 at 14:10 2 Drop the link in a Redirect Checker. See what it comes up with. And does this work in a browser? What about a browser running in private/incognito mode with data cleared? –FakeRainBrigand Feb 2 '12 at 14:10 i checked with Redirect Checker - it redirects to himself. it does work in a browser because the browser supports cookies –yossi Feb 2 '12 at 14:36 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote accepted Here's an example from Python documentation, adjusted to your code: import cookielib, urllib2 cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) request = urllib2.Request(url) response = opener.open(request) share|improve this answer answered Feb 2 '12 at 15:49 DzinX 23.2k74371 Worked perfectly. Was messing around with Selenium and Spynner, but really it seems that I can use urllib2 for everything, even with cookies and form data and redirects and session ids that expire. –user984003 Mar 21 '13 at 14:19 add a comment| Your Answer draft saved draft
6 Nursey takes a break, cookiejake in for -bird noises- 8 CheesyMacgyver joins Circa eSports 3 highfive quits, slemnish joins EVL Gaming 12 Insomnia58 highlight movie released 61 Upcoming Events 5d › ETF2L S25 W5: yolotech vs. http://www.teamfortress.tv/13900/python-urllib2-help top5rocket 3 2d › ETF2L S25 W5: 3/6 vs. LEGO 0 1d › ETF2L S25 W5: ChampGG.K! vs. Crowns eSports Club 0 19h › ETF2L S25 W5: Animate vs. Danger Dogs 0 ESEA S23 W5: froyotech vs. -bird http://ru-python.livejournal.com/309923.html noises- 11 ESEA S23 W5: EVL Gaming vs. Circa eSports TF2 7 ETF2L S25 W4: ChampGG.K! vs. LEGO 3 ETF2L S25 W4: Animate vs. sauna slayers 5 Recent Discussion Sp00ky Halloween Stories 12 Donald Trump 595 ESEA-IM S23 http error Happenings/Discussion 647 Fastest way to improve 20 ESEA-O S23 Happenings/Discussion 570 Happy Bob and 6 Rockets 21 first time u played tf2 66 ETF2L S25 W5: yolotech vs. top5rocket 3 cheater in dm server vol 2. 46 old school 104 ETS Lan? 4 Serious question 42 NA East potential LAN 3 Satisfying gifs 24 Null Movement Scrip Not Loading 1 Live Streams TF.TV TF2 CS:GO Dota2 stabbystabby puibs then UGC Platinum HL match 6:30PM PST !!! http error 302 58 Skeez hello 23 Dreamboat The Bastard Esport 9 Cayda TF2 Until I Wake Up 7 Saturn Screwing around on Hightower 7 JoinedSenses Surf | Jump 2 Trilbys catface returns 0 truktruk Food then Stardew after [almost at 250 million subs] - Marketplace.tf 135 ruwin [Top 20] This is how you climbin' out of diamin'! ruwHAA 50 tehs4ndman TAKE A SHOT | !KNIFE FLIP KNIFE GIVEAWAY AT 7500 FOLLOWS 11 kos i solo queue until death 4 ghos7ayama [Elysium] bird farm then alts at 9EST || @ghos7ayama_ow 2 B|R|A|V|O Road to 100 followers lol 1 lee playing h1 with tf2 people 1 Slardel slardel 0 Nu low% speedruns 0 stabbystabby puibs then UGC Platinum HL match 6:30PM PST !!! 58 Sud [TF2/60fps/SALT] Ew video games at 5am 33 Sir_Pink #PinkNation - Powered By Wolf Beats 26 skeez_ hello 24 Dreamboat_ The Bastard Esport 9 TheRaidParade Jump In & Play With Us! | HAT GIVEAWAY | !ip !discord 9 Saturnity Screwing around on Hightower 7 inkytheblot [pc] sup 7 JohnnyValor Casual Pubbin', how hard can I be called out? 7 citrineCayda TF2 Until I Wake Up 7 cukei watcha cancer sniper main play 4 Vulpinal We're All Mad Here| Road to 500 4 TriscyTV Glayuss. Scout glayuss. 3 ezrik1414 TF2 Plat Demo POV 3 blueskys643 Playing some tf2 3 JoinedSenses Surf | Jump 3 MatthewPlaysPC TF2 with
ru_python Log in Or connect using: Facebook Twitter VK Google+ Mail.ru OpenID Error Username: Error Password: Forgot password? Remember me Log in Forgot password? Create an Account Your OpenID URL: Log in Руслан Валиев (unixblog) wrote in ru_python, 2011-08-25 09:33:00 Руслан Валиев unixblog ru_python 2011-08-25 09:33:00 Previous Share Next urllib2 redirect error Всем привет.Столкнулся со странной проблемой. При попытке открыть urllib2'ом эту страницу, получаю:urllib2.HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loopЯ уж думал, ему еще какие-нибудь заголовки надо, но, видимо, не в том дело. Не подскажите, что я упустил? Спасибо.
>>> import urllib2
>>> o = urllib2.build_opener(urllib2.HTTPCookieP
>>> urllib2.install_opener(o)
>>> o.open('https://clientzone.eastcapital.c
Traceback (most recent call last):
File "
File "/usr/lib/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
File "/usr/lib/python2.6/urllib2.py", line 510, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python2.6/urllib2.py", line 429, in error
result = self._call_chain(*args)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 605, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/usr/lib/python2.