2007
09.22

libgmail es, en palabras de su autor, una biblioteca hecha puramente en python que provee acceso a tu cuenta gmail via web.

Lo uso y lo encuentro muy útil. Sin embargo, dentro de mi organización, debo conectarme a internet mediante un proxy/cortafuegos HTTP/HTTPS. Las conexiones directas a internet están filtradas, así que desarrollé un pequeño hack para hacerlo funcionar tras una conexión con proxy.

Básicamente cogí el código de esta receta de ASPN, y derivé la clase urllib proxied transport para crear una nueva.

Para usar tras un proxy, puedes copiar el ejemplo de libgmail, y definir el proxy así:

Parcheé el archivo libgmail.py y escribí la clase derivada en otro: gmail_transport.py. Necesitarás copiar tanto el archivo gmail_transport.py como la versión modificada de libgmail.py (sobreescríbela) en el mismo directorio en el que libgmail.py está instalado.

También está disponible el archivo diff (parche) para la versión libgmail-0.6.1.2.

Actualización (2007-10-06): Es posible usar un proxy con autenticación. Para ello utiliza la dirección proxy del ejemplo anterior como user:password@myproxy.org:3128 donde user y password son el usuario y contraseña que requiere tu proxy. Tienes que volver a descargarte el archivo gmail_transport.py.

Ahora, el ejemplo para usarlo a través de un proxy con autenticación sería como el que sigue:

Share
  1. 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

    Like or Dislike: Thumb up 0 Thumb down 0

  2. 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…

    Like or Dislike: Thumb up 0 Thumb down 0

  3. 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’

    Like or Dislike: Thumb up 0 Thumb down 0

  4. 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 !!!

    Like or Dislike: Thumb up 0 Thumb down 0

  5. 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.

    Like or Dislike: Thumb up 0 Thumb down 0

  6. 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 ?

    Like or Dislike: Thumb up 0 Thumb down 0

  7. 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

    Like or Dislike: Thumb up 0 Thumb down 0

  8. Good Conception!

    😕 “407 Proxy Authentication Required”

    Like or Dislike: Thumb up 0 Thumb down 0

  9. 💡 Good news 💡

    Release Name: 0.1.7

    Changes: Added support for proxy servers for libgmail (both passwordless and password-ful proxies). This came from a patch by Jose Rodriguez, for which we’re very thankful.

    >> https://sourceforge.net/project/shownotes.php?release_id=545286

    Like or Dislike: Thumb up 0 Thumb down 0

  10. Sweet! 😯 I just tried your code and it worked perfectly!!! 😆 Many thanks and great job there, Boriel!

    Like or Dislike: Thumb up 0 Thumb down 0

  11. 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).

    Like or Dislike: Thumb up 0 Thumb down 0

  12. 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.

    Like or Dislike: Thumb up 0 Thumb down 0

  13. 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!!! 🙂

    Like or Dislike: Thumb up 0 Thumb down 0

  14. 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!

    Like or Dislike: Thumb up 0 Thumb down 0

  15. 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!

    Like or Dislike: Thumb up 0 Thumb down 0