上下文: 所以我试图构建一个python程序,它将POST请求发送到特定的.php文件,并返回输出。我做了一些研究,这是我到目前为止的代码:
<Grid>
<StackPanel Orientation="Horizontal" DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Label Content="{Binding Label}" Width="60"></Label>
<TextBox Text="{Binding TextBoxContent}" Width="60"/>
</StackPanel>
</Grid>
该代码适用于普通网站,例如www.google.com,但如果我尝试访问php页面,则会出现此错误:
def ForcePush():
params = urllib.urlencode({'log': 'admin', 'pwd':'password'})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain", "Accept-Language":"en-Us,en;q=0.5" ,
"Referer":"http://192.168.18.138/wp-login.php"}
conn = httplib.HTTPConnection(raw_input("Where would you like to browse to: "))
conn.request("POST", "", params, headers)
response = conn.getresponse()
data = response.read()
print data
conn.close()
如果您想知道,我正在制作程序,以便在VMWare上枚举Mr.Robot难以驾驭的VM的WPAdmin。为教育目的这样做。这是我试图模仿的请求:
Traceback (most recent call last):
File "WPEnum.py", line 24, in <module>
ForcePush()
File "WPEnum.py", line 18, in ForcePush
conn.request("POST", "", params, headers)
File "C:\Python27\lib\httplib.py", line 1057, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1097, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 1053, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 897, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 859, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 836, in connect
self.timeout, self.source_address)
File "C:\Python27\lib\socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed
我知道我没有所有的标题,但这似乎并不是错误所暗示的错误。有谁知道问题是什么?
答案 0 :(得分:0)
正如您从异常中看到的那样,您有与连接相关的错误(在打开套接字时),因此您在请求中使用的主机/端口显然是错误的,或者由于某种原因无法从python环境(显然是从系统)访问。
调试尝试使用curl或wget获取相同的页面(即使使用GET方法)。
curl http://my_host:my_port/my_page.php