【问题标题】:How to make a http request with cookies using urllib3 Python library? [duplicate]如何使用 urllib3 Python 库使用 cookie 发出 http 请求? [复制]
【发布时间】:2012-08-28 19:33:11
【问题描述】:

可能重复:
Python urllib3 and how to handle cookie support?

我正在尝试使用已发布的 cookie 从网页中检索源代码并将源代码写入 txt 文件。如果我删除 cookies=cookie 部分,我可以检索源代码,但我需要以某种方式将 cookie 与 http 请求一起发送。

output = open('Filler.txt', 'w+')
http = urllib3.PoolManager()
cookie =('users' , '1597413515')
r = http.request('http://google.com' , 'GET' , cookies=cookie)
output.write(r.data)
output.close()

我得到一个 KeyError:无

【问题讨论】:

    标签: python http cookies httprequest urllib3


    【解决方案1】:

    您必须在发送请求之前将 cookie 添加到标头中。你见过Python urllib3 and how to handle cookie support?

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 1970-01-01
      • 2020-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 2019-02-13
      • 2010-10-15
      • 2020-12-31
      相关资源
      最近更新 更多