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
Cisplatin
  • 2,860
  • 3
  • 36
  • 56
  • 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) – Joran Beasley Feb 04 '16 at 00:00
  • Are you in enterprise network? – user1157751 Feb 04 '16 at 00:01
  • 1
    @JoranBeasley Fixed; the code I was testing with was correct. – Cisplatin Feb 04 '16 at 00:03
  • see http://stackoverflow.com/questions/10588644/how-can-i-see-the-entire-http-request-thats-being-sent-by-my-python-application ... you might be able to see some extra debug info about what is going on – Joran Beasley Feb 04 '16 at 00:06
  • @JoranBeasley added the results to the question. – Cisplatin Feb 04 '16 at 00:09
  • 1
    is this a virtualbox? or a physical machine? I would likely blame the network configuration (ie firewall/proxy/or VM network adapter) – Joran Beasley Feb 04 '16 at 00:12
  • What evidence do you have that you can fetch that URL from the remote machine at all? From the command line of your ssh-destination, can you `wget` or `curl` that URL? Can you `telnet www.google.com 443` (or port `80`, for that matter)? Can you `ping www.google.com`? Run through all your usual network-troubleshooting tricks _from the host you've `ssh`ed into_. – Kevin J. Chase Feb 04 '16 at 03:32

2 Answers2

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

Zada Zorg
  • 2,778
  • 1
  • 21
  • 25
1

Try this (assuming you are using python3):

from urllib.request import urlopen
r = urlopen('https://www.google.com').read()
felixbade
  • 1,009
  • 3
  • 10
  • 18