python - 如何使用 auth 进行 urllib POST?

标签 python python-3.x urllib

我尝试使用 urllib 进行 POST 调用(python 3.5),但无法弄清楚。有很多关于如何制作 POST call without auth 的示例。或call with auth, but GET ...我正在努力将 2 和 2 放在一起!有人可以帮我提供代码吗?

最佳答案

你可以尝试:

import urllib.request  

auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='name',
                          uri='url',
                          user='user',
                          passwd='pass')
opener = urllib.request.build_opener(auth_handler)
urllib.request.install_opener(opener)
req = urllib.request.Request(url=some_url, data=data, method='POST')
urllib.request.urlopen(req)

关于python - 如何使用 auth 进行 urllib POST?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45676263/

相关文章:

python - 使用 urllib.request 验证 HTTPS 证书

python - Linux 服务器上的 HTTP 错误 429,但不是我的本地计算机?

python - Python 请求中的logging.NullHandler 和__init__.py 文件位置

python - 如何让pyttsx模块的语音变慢

python - 为什么需要 'b' 来使用 Base64 编码字符串?

python - 模拟浏览器访问加载所有html元素

python - 在 Python 中使用原子分组的最佳方式?

python - 如何向量化此操作

python - 如何使用 StackedInline 类使现有模型对象只读,但也能够创建新模型对象?

python - 如何动态迭代上游任务的输出以在 Airflow 中创建并行任务?