Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL request from Python

Tags:

python

http

get

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!

like image 272
Elo97234c Avatar asked Jul 18 '26 15:07

Elo97234c


1 Answers

Use requests module

import requests as req
url = 'http://192.168.1.101/value=1'
resp = req.get(url)
print(resp.text) # Printing response
like image 184
Rithesh B Avatar answered Jul 20 '26 04:07

Rithesh B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!