本文主要是介绍Python模拟HTTPS请求返回HTTP 401 unauthorized错误,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Python模拟HTTPS请求返回HTTP 401 unauthorized错误
在文章 Python Web中REST API使用示例——基于云平台+云服务打造自己的在线翻译工具 中,用到了Python模拟HTTPS请求的功能;
开始是使用的 httplib模块,代码如下:
header = {"Content-type": "application/json", "Accept": "*/*" }params = { 'source':'en', 'target':'es', 'text':match.group(1) } data = urllib.urlencode(params)surl = urlparse('https://gateway.watsonplatform.net/language-translation/api/v2/translate')#surl = urlparse('https://www.baidu.com/')resContent = ''try:conn = httplib.HTTPSConnection(surl.netloc) conn.request('GET', surl.path + '?' + data)response = conn.getresponse()resContent &
这篇关于Python模拟HTTPS请求返回HTTP 401 unauthorized错误的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!