使用Python中的基本身份验证进行HTTP POST的最简洁方法是什么? [英] What is the cleanest way to do HTTP POST with basic auth in Python?
本文介绍了使用Python中的基本身份验证进行HTTP POST的最简洁方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python中使用Basic Auth进行HTTP POST的最简洁方法是什么?
What is the cleanest way to do HTTP POST with Basic Auth in Python?
仅使用Python核心库。
Using only the Python core libs.
推荐答案
说真的,只需使用 requests
:
Seriously, just use requests
:
import requests
resp = requests.post(url, data={}, auth=('user', 'pass'))
这是一个纯python库,安装就像 easy_install requests
或 pip install requests
一样简单。它有一个非常简单易用的API,它修复了 urllib2
中的错误,所以你不必这样做。不要因为愚蠢的自我要求而让你的生活更加艰难。
It's a pure python library, installing is as easy as easy_install requests
or pip install requests
. It has an extremely simple and easy to use API, and it fixes bugs in urllib2
so you don't have to. Don't make your life harder because of silly self-imposed requirements.
这篇关于使用Python中的基本身份验证进行HTTP POST的最简洁方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文