4

I'm trying to make a simple HTTP request in Python in an SSH terminal:

from requests import get
r = get("https://www.google.com")

However, this command just stalls to infinity. This does not happen when not in SSH.

Is there any way to send the request such that it goes through?

Thanks ahead of time.

EDIT: Running the logging in Joran's link yields only the following line:

INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): www.google.com
7
  • your import does not match your code ... this question really doesnt make sense ... it works fine in my ssh terminal (and ever ssh terminal I have ever tried) Commented Feb 4, 2016 at 0:00
  • Are you in enterprise network? Commented Feb 4, 2016 at 0:01
  • 1
    @JoranBeasley Fixed; the code I was testing with was correct. Commented Feb 4, 2016 at 0:03
  • see stackoverflow.com/questions/10588644/… ... you might be able to see some extra debug info about what is going on Commented Feb 4, 2016 at 0:06
  • 1
    is this a virtualbox? or a physical machine? I would likely blame the network configuration (ie firewall/proxy/or VM network adapter) Commented Feb 4, 2016 at 0:12

2 Answers 2

2

First, check that you have ability to reach URL using some system-wide tool, like curl: curl -I "https://www.google.com". In case, you will have not timeout error, and got success response, my answer is not for you :)

You code can run forever, just because there is not timeout defined for socket connections. And if for some reason your system is not able to read from socket (at low level), you have to wait for long time.

http://docs.python-requests.org/en/latest/user/quickstart/#timeouts

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

Comments

1

Try this (assuming you are using python3):

from urllib.request import urlopen
r = urlopen('https://www.google.com').read()

3 Comments

I was using urlllib2 before and was having the same error, not sure this will work.
why do you think this will work if requests wont? @felixbade
@JoranBeasley ahh, I thought there was just a typo in the code

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.