1

When I try the following code, requests library not returning any response

import requests
url = "http://www.nodefarm.com/"
resp = requests.get(url, timeout=5.0)
print resp

Can someone tell me why my code got stuck in line 3?

P.S: I'm not receiving any error.

When I visit http://www.nodefarm.com/ in my browser, site works fine

7
  • do you have the requests library installed? is the location of the install in your python path? Commented May 30, 2014 at 0:54
  • If he didn't, he would get an import error on line 1. It wouldn't even make it to the line he gets stuck on. Commented May 30, 2014 at 0:55
  • @deweyredman Yes I have that library installed. I'm using that library for months. All other urls working except this one. Its just 3 lines of code. So you may test that in your shell. Commented May 30, 2014 at 1:01
  • Reason why I was asking is because context would be nice...For example is this is on a windows system and python hasn't been whitelisted through the firewall that might explain what's going on. Commented May 30, 2014 at 1:01
  • This helps, let me see if i can figure something out Commented May 30, 2014 at 1:01

2 Answers 2

4

well, the thing is, it's not exactly getting stuck.

that url returns an apparently endless stream of data, the first few lines of which look a bit like so:

ICY 200 OK
icy-notice1:<BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR>
icy-notice2:SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR>
icy-name:RADIO HANG 106  FM BATAM - SVR USA
icy-genre:Misc
icy-url:http://live.hang106.com/;stream.nsv
content-type:audio/mpeg
icy-pub:1
icy-br:48

Pulling it up in vlc, it seems to be talk radio in a language I don't speak.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok. Can you tell me how to handle this problem in my program?
4

IfLoop is correct that the page is streaming data. You can use requests with stream=True and iterate to see the data for yourself:

import requests
url = "http://www.nodefarm.com/"
resp = requests.get(url, stream=True)
for line in resp.iter_lines():
    if line:
        print line

Not sure how much this will help though.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.