代理背后的PyQt + QtWebkit [英] PyQt + QtWebkit behind a proxy
问题描述
我正在编写一个PyQt(全功能Qt库的Python绑定)应用程序,我的应用程序的一小部分需要一个Web浏览器(提示,OAuth)。所以我开始使用QtWebkit,顺便说一下这很棒。唯一的障碍是我想允许代理后面的用户使用我的应用程序。
I'm writing a PyQt (Python bindings for the all-powerful Qt library) application and a small part of my application needs a web browser (hint, OAuth). So I started using QtWebkit, which is fantastic by the way. The only hitch is I would like to allow users behind a proxy to use my application.
我已经阅读了QtNetwork包中的QNetworkProxy类,并认为应该这样做招。唯一的问题是当我创建和应用代理时,它在HTTP上工作得很好,但是当我传递HTTPS(SSL)URL时,它会给我以下错误:
I have read about the QNetworkProxy class in the QtNetwork package and figure it should do the trick. The only problem is when I create and apply the proxy, it works just fine over HTTP, but when I pass it a HTTPS (SSL) URL, it gives me the following errors:
QSslSocket: cannot call unresolved function SSLv3_client_method
QSslSocket: cannot call unresolved function SSL_CTX_new
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function ERR_get_error
QSslSocket: cannot call unresolved function ERR_error_string
注意:当我运行时......
Note: when I run...
QtNetwork.QSslSocket.supportsSsl()
..它返回false。这就是我的问题的证据。
.. it returns false. So that's proof of my problem.
这是我的主要代码(在我创建QApplication之前就已经存在):
Here's my main code (it's right before my creationg of my QApplication):
proxy = QtNetwork.QNetworkProxy()
proxy.setType(QtNetwork.QNetworkProxy.Socks5Proxy)
proxy.setHostName('localhost');
proxy.setPort(1337)
QtNetwork.QNetworkProxy.setApplicationProxy(proxy);
我从这里但是这个例子是用C ++编写的,而不是Python,所以我不确定我是否正确翻译它。这可能是问题所在。
I got the code from here but the example was written in C++, not Python so I'm not quite sure if I translated it properly. That could be the problem.
编辑:我在SOCKS5和HTTP代理上尝试了它们,它们都抛出相同的错误。
I've tried it over a SOCKS5 and an HTTP proxy and they both throw the same error.
推荐答案
我正在使用Python 2.6和PyQt 4.7.4开发Windows XP(32位)。原因......
I was working on Windows XP (32-bit) with Python 2.6 and PyQt 4.7.4. The reason that...
QtNetwork.QSslSocket.supportsSsl()
返回 false 是因为我没有在系统中安装 OpenSSL二进制文件。
was returning false was because I had not installed OpenSSL binaries to my system.
为了解决这个问题,我去了这里下载二进制文件。在他们正确安装之前,我还必须从Microsoft安装 Visual C ++ 2008 Redistributables 。
To solve the problem I went here to download the binaries. Before they would properly install I had to also get the Visual C++ 2008 Redistributables install from Microsoft.
现在一切正常!
这篇关于代理背后的PyQt + QtWebkit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!