【问题标题】:URL request from Python来自 Python 的 URL 请求
【发布时间】:2017-08-20 15:13:22
【问题描述】:

我有一个服务器正在运行,它总是在监听 value 字段
我可以通过 URL 从网络浏览器发出请求,

Eg: http://192.168.1.101/value=1

如何从 Python 发出这样的请求,我尝试了上面的代码,但它似乎不起作用。

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

我的服务器正在监听上述格式。(GET)

GET /value=1 HTTP/1.1

干杯!

【问题讨论】:

    标签: python http get


    【解决方案1】:

    使用请求模块

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

    【讨论】:

    • 我得到一个错误,引发 RemoteDisconnected("Remote end closed connection without" requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response' ,))
    • 尝试任何其他网址而不是本地网址。比如说,url = "google.co.in"
    • 现在可以使用了!愚蠢的错误:P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 2021-02-20
    • 2013-06-12
    • 1970-01-01
    相关资源
    最近更新 更多