Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:Python中的Post请求_Python_Post_Urllib2_Urllib - Fatal编程技术网

错误:Python中的Post请求

错误:Python中的Post请求,python,post,urllib2,urllib,Python,Post,Urllib2,Urllib,我正在尝试登录到 这是我写的剧本 import urllib import urllib2 url = 'http://site21.way2sms.com/content/index.html' values = {'username' : 'myusername', 'password' : 'mypassword'} headers = {'Accept':'*/*', 'Accept-Encoding':'gzip, deflate, sd

我正在尝试登录到

这是我写的剧本

import urllib
import urllib2

url = 'http://site21.way2sms.com/content/index.html'
values = {'username' : 'myusername',
          'password' : 'mypassword'}

headers = {'Accept':'*/*',
            'Accept-Encoding':'gzip, deflate, sdch',
            'Accept-Language':'en-US,en;q=0.8',
            'Cache-Control':'max-age=0',
            'Connection':'keep-alive',
            'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
            'If-Modified-Since':'Fri, 13 Nov 2015 17:47:23 GMT',
            'Referer':'https://packetforger.wordpress.com/2013/09/13/changing-user-agent-in-python-requests-and-requesocks-and-using-it-in-an-exploit/',
            'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36'}


data = urllib.urlencode(values)
req = urllib2.Request(url, data, headers=headers)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
我从网站上得到了回复。但它是加密的或类似的:

��:�����G��ʯ#��C���G�X�*�6�?���ך��5�\���:�tF�D1�٫W��<�bnV+w\���q�����$�Q��͇���Aq`��m�*��Օ���)���)�

��:�����G��ʯ#��C���G�X�*�6.�?���ך��5.�\���:�tF�D1�٫W�� 该页面上的表单不会发回相同的URL,而是发回。

最有可能的情况是,由于您明确表示将接受gzip编码,因此内容确实是gzip ped。如果你不想要这个,不要传递那个接受编码头。谢谢Daniel,这很有帮助!但我仍然在登录页面上。如何成功登录?登录后需要修改哪部分代码才能获得页面的“html”?