简体   繁体   English

机械化将登录表单从http提交到https

[英]Mechanize submit login form from http to https

I have a web page containing a login form which loads via HTTP, but it submits the data via HTTPS. 我有一个网页,其中包含通过HTTP加载的登录表单,但它通过HTTPS提交数据。

I'm using python-mechanize to log into this site, but it seems that the data is submitted via HTTP. 我正在使用python-mechanize登录这个站点,但似乎数据是通过HTTP提交的。

My code is looks like this: 我的代码看起来像这样:

import mechanize
b = mechanize.Browser()
b.open('http://site.com')
form = b.forms().next()  # the login form is unnamed...
print form.action        # prints "https://login.us.site.com"
form['user'] = "guest"
form['pass'] = "guest"
b.form = form
b.submit()

When the form is submitted, the connection is made via HTTP and contains something like: 提交表单时,连接是通过HTTP进行的,包含以下内容:

send: 'POST https://login.us.site.com/ HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 180\r\nHost: login.us.site.com\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'...

Can anyone confirm this and eventually post a solution so that the form is submitted via HTTPS? 任何人都可以确认这一点并最终发布解决方案,以便通过HTTPS提交表单吗?

Later edit: 稍后编辑:

1) I'm using a HTTP proxy for http/https traffic (set in the environment - Linux machine) 1)我正在使用HTTP代理进行http / https流量(在环境中设置 - Linux机器)
2) I've watched the traffic with Wireshark and I can confirm that the traffic is sent via normal HTTP (I can see the content of the POST and mechanize doesn't send the same requests to the proxy as a webbrowser - the latter sends CONNECT login.us.site.com:443, while mechanize only POSTs https://login.us.site.com ). 2)我用Wireshark观察了流量,我可以确认流量是通过普通HTTP发送的(我可以看到POST的内容,机械化不会像webbrowser那样向代理发送相同的请求 - 后者发送连接login.us.site.com:443,同时仅机械化POST https://login.us.site.com )。 However, I don't know what happens to the data as it leaves the proxy; 但是,我不知道数据离开代理时会发生什么; perhaps it establishes a ssl connection to the target site? 也许它建立了与目标站点的ssl连接?

mechanize uses urllib2 internally and the later had a bug: HTTPS over (Squid) Proxy fails . mechanize内部使用urllib2 ,后者有一个bug: HTTPS over(Squid)代理失败 The bug is fixed in Python 2.6.3, so updating Python should solve your problem. 该错误在Python 2.6.3中得到修复,因此更新Python应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM