URL request from Python

风格不统一 提交于 2019-12-25 19:39:15

问题


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!


回答1:


Use requests module

import requests as req
url = 'http://192.168.1.101/value=1'
resp = req.get(url)
print(resp.text) # Printing response


来源:https://stackoverflow.com/questions/45783644/url-request-from-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!