gpt4 book ai didi

python - 使用 Python 和 urllib2 时设置 Host-header

转载 作者:太空狗 更新时间:2023-10-29 21:35:41 25 4
gpt4 key购买 nike

我正在使用我自己的解析器,并且想使用 urllib2 连接到 IP(不在 urllib2 中解析),我想自己设置 HTTP 主机 header 。但是 urllib2 只是忽略了我的主机头:

txheaders = { 'User-Agent': UA, "Host: ": nohttp_url }
robots = urllib2.Request("http://" + ip + "/robots.txt", txdata, txheaders)

最佳答案

您已将 ": " 包含在 "Host" 字符串中。

txheaders = { "User-Agent": UA, "Host": nohttp_url }
robots = urllib2.Request("http://" + ip + "/robots.txt", txdata, txheaders)

关于python - 使用 Python 和 urllib2 时设置 Host-header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3520966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com