4

I have a Server running and its always listening to the value field
I can make a requests from a web browser from the URL,

Eg: http://192.168.1.101/value=1

How can i make a request like this from Python, i tried the above code but it doesnt seem to work.

from urllib.parse import urlencode
from urllib.request import Request, urlopen
url = 'http://192.168.1.101/value=1'
request = Request(url)

My server is listening in the above formate.(GET)

GET /value=1 HTTP/1.1

Cheers!

Elo97234c
  • 163
  • 1
  • 4
  • 15

1 Answers1

10

Use requests module

import requests as req
url = 'http://192.168.1.101/value=1'
resp = req.get(url)
print(resp.text) # Printing response
Rithesh B
  • 198
  • 1
  • 9
  • I get an error, raise RemoteDisconnected("Remote end closed connection without" requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) – Elo97234c Aug 20 '17 at 15:27
  • just try any other url instaead of local one. say, url = "https://www.google.co.in/" – Rithesh B Aug 20 '17 at 15:30
  • It Works now! Silly mistake :P – Elo97234c Aug 20 '17 at 15:35