09.22
libgmail is, in words of its author, a pure python binding to provide access to your gmail account.
I’m using it and find it very useful. However, within my organization, I must connect to the internet via an HTTP/HTTPS proxy firewall. Direct internet connections are filtered, so I developed a hack to make it to work via an HTTP(S) proxied connection.
Basically I ripped the code from this ASPN snippet, and derived the urllib proxied transport to create a new one.
To use it behind a proxy, you can copy the libgmail example, and define the proxy this way:
import libgmail libgmail.PROXY_URL = 'www.myproxy.org:3128' # Define the proxy. ga = libgmail.GmailAccount("google@gmail.com", "mymailismypass") ga.login() folder = ga.getMessagesByFolder('inbox') for thread in folder: print thread.id, len(thread), thread.subject for msg in thread: print " ", msg.id, msg.number, msg.subject print msg.source
I patched the libgmail.py file and write the proxied transport in another one: gmail_transport.py. You will need to copy both the file gmail_transport.py and the modified version of libgmail.py (overwrite it) into the same directory libgmail.py is installed.
There is also a diff file available, for libgmail-0.6.1.2.
Update (2007-10-06): It’s now possible to use proxy authentication. To do it so, you must use the proxy host address on the previous example this way: user:password@myproxy.org:3128 where user and password are your proxy user and password respectively. You’ll have to download again the file gmail_transport.py.
Now, the example to use it behind a proxy requiring with user/passwd authentication is like this:
import libgmail # Connect from behind a proxy www.myproxy.org:3128 using # proxy authentication user = 'john', password = 'proxy4321' libgmail.PROXY_URL = 'john:proxy4321@www.myproxy.org:3128' # Define the proxy ga = libgmail.GmailAccount("google@gmail.com", "mymailismypass") ga.login() folder = ga.getMessagesByFolder('inbox') for thread in folder: print thread.id, len(thread), thread.subject for msg in thread: print " ", msg.id, msg.number, msg.subject print msg.source
Related posts:
- XML-RPC over the proxy server
- Self-replication
- Python with elegance
- Read/Write removable devices under NTFS in Kubuntu


what website can i use to unblock myspace or yahoo or facebook or any websites in the schools library?
i wanna check it on school thats why
plz help
thx
Hello,
I am having the same issue as well…
File “/libgmail.py”, line 335, in login
pageData = self._retrievePage(req)
File “/libgmail.py”, line 385, in _retrievePage
resp = self.opener.open(req)
File “/usr/lib/python2.5/site-packages/mechanize/_opener.py”, line 181, in open
response = urlopen(self, req, data)
File “/usr/lib/python2.5/urllib2.py”, line 399, in _open
‘_open’, req)
File “/usr/lib/python2.5/urllib2.py”, line 360, in _call_chain
result = func(*args)
File “/usr/lib/python2.5/site-packages/mechanize/_http.py”, line 727, in https_open
key_file, cert_file = self.client_cert_manager.find_key_cert(
AttributeError: ‘int’ object has no attribute ‘find_key_cert’
I was forced to use an older version of 0.8 libgmail because the gmail_transport doesn’t work with 1.11, but recent changes have forced me back to 1.11, and now I can only send directly, and not behind a firewall…
I have error when using proxy (privoxy, 192.168.0.1:8118)
Traceback (most recent call last):
File “Z:\kerja\odesk\16-gmail\root\test.py”, line 6, in <mo
ga.login()
File “Z:\kerja\odesk\16-gmail\root\libgmail.py”, line 307,
pageData = self._retrievePage(req)
File “Z:\kerja\odesk\16-gmail\root\libgmail.py”, line 349,
resp = self.opener.open(req)
File “Z:\kerja\odesk\16-gmail\root\mechanize\_opener.py”, l
response = urlopen(self, req, data)
File “C:\Python25\lib\urllib2.py”, line 399, in _open
‘_open’, req)
File “C:\Python25\lib\urllib2.py”, line 360, in _call_chain
result = func(*args)
File “Z:\kerja\odesk\16-gmail\root\mechanize\_http.py”, lin
n
key_file, cert_file = self.client_cert_manager.find_key_c
AttributeError: ‘int’ object has no attribute ‘find_key_cert’
Hi again, I downloaded the libgmail-0.1.10 from the source forge, and installed it:
1) setup build
2) setup install
but still the same error !!!
Hi, Hosi
Download the very latest libgmail patch from the sourceforge web. It fix this problem (and many others).
This problem appeared after Google changed his API.
Hi every body, this is my output :
HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Moved Temporarily
Why ?
sprzedam (#8):
Are you using the authentication line?
(ej. user john, passwd: proxy4321) =>
libgmail.PROXY_URL = ‘john:proxy4321@www.myproxy.org:3128′ # Define the proxy
Good Conception!
>> https://sourceforge.net/project/shownotes.php?release_id=545286
Sweet!
I just tried your code and it worked perfectly!!!
Many thanks and great job there, Boriel!
cci[RR]us (#3):
I’ve already patched it. Download gmail_transport.py and use user:passwd@your.proxy.org:3128 as your proxy. It should work now.
Note (for everybody reading this): 3128 is just a port example. Replace 3128 with your proxy port (usually 3128 or 8080).
Yes, I’ve sent the patch to the developers mainling list and they say it will probably be included in future releases.
I will try to send them the new patch with User/Pass support.
Thanks for the continued work!!!
I must say that your enhancement for supporting HTTP proxy is a godsend, and should be added into libgmail. Proxied environments are very common nowadays and the lack of proxy support severely limits libgmail capabilities.
Have you considered adding your code into libgmail’s CVS? I’m sure many people would appreciate it!!!
Hi, cci[RR]us
I’m working on the User/Password proxy scheme, and it will be implemented as soon as possible (probably today).
Stay tuned!
Hi,
Thanks to your post, I am able to write a program to upload files to my Gmail account over a HTTP(S) proxy. However, there are cases when the proxy server requires authentication and the program fails:
urlopen error Proxy connection failed:
407 Proxy Authentication Required
Do you know how to enable proxy authentication? Thanks!