gmail-parser.py failure

VastOne

Issue with gmail-parser.py script I have been running forever...

I recently had to reinstall my main build system and in the rebuild, I cannot get the gmail-parser.py script to run anymore.. It still works fine on all other machines so it is definitely something I have not installed (something I have forgotten...)

Here is the conky feedback when it is run

  File "/home/vastone/gmail_parser.py", line 46, in <module>
    f = auth()  # Do auth and then get the feed
  File "/home/vastone/gmail_parser.py", line 30, in auth
    feed = f.read()
  File "/usr/lib/python2.7/socket.py", line 355, in read
    data = self._sock.recv(rbufsize)
  File "/usr/lib/python2.7/ssl.py", line 766, in recv
    return self.read(buflen)
  File "/usr/lib/python2.7/ssl.py", line 653, in read
    v = self._sslobj.read(len)
socket.error: [Errno 0] Error


I have everything the script installed (feedparser etc) but no go to get it to run

Anyone spot what I am missing?
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

#1
As I recall there are 2-3 dependencies for that script - one was called py-parser, python-parser or something like that and pulled in the other 2.

I vaguely remember reading a thread about this where you solved it - you have the old #! forum bookmarked? If you search that, you may find your old thread.

this maybe -

gmail python script

python-feedparser maybe
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

Yes.. I wrote a How To over there for it... :D

The needed app is python-feedparser and that is correctly installed... everything looks as if it should function fine but I am cannot get it to go..

VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

#3
beat me to it  :D :D

Clean [re]-install of your system?

Next guess would be you need python 2.7 but Debian in python 3 by default now.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

Yes... a clean install

But 2.7 and 3.0 are both still installed as default although I did run vsido-welcome so it could have been installed during that but I do not believe so
VSIDO      VSIDO Change Blog    

    I dev VSIDO

VastOne

I have also spent most of today google-fu the fuck out of this issue and have not been able to resolve...

I have found a nice bash alternative that just shows me I have new emails (count)

If we solve it fine, if not fine.... :D
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

Does your gmail-parser.py run in a terminal?

Might be a ...wait for it ... conky issue.

I've had conky barf on some older configs after doing a reinstall, usually it will not run a bash script. A couple times I rewrote the conky config.

Should be conky 1.10 on your new install, correct? The other machines conky 1.9 or 1.10? And is your conkyrc in 1.10 format?
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

Same conky on all systems...

Good thought... :D
VSIDO      VSIDO Change Blog    

    I dev VSIDO

jedi

Hey VastOne!  A Cub's world series after all...   8)

I've noticed with a couple of different python scripts, you need to either specify in the code that it is indeed python2, or start it with "python2" instead of just "python".  Give it a try and good luck!  And yes both Pythons are installed in VSIDO by default.  You might also need to add it to the $PATH...  ;D
Forum Netiquette

"No matter how smart you are you can never convince someone stupid that they are stupid."  Anonymous

VastOne

Same failures running it with python2 as with regular python

Using python3 gets me further but syntax errors pop up with it, which means more than anything the script needs a rewrite

I am only saddened by this as I have been using this particular script for as long as I have been using Linux... quite a long time

Yes.. the Cubs are legit...
VSIDO      VSIDO Change Blog    

    I dev VSIDO

hakerdefo

Just make sure the following packages are there (they should be, most likely),


openssl
python-openssl
python3-openssl


If they are there and/or installing them doesn't solve the problem then open 'gmail-parser.py' in text-editor and add either of the following snippets at the top of the script,


import ssl
ssl.PROTOCOL_SSLv23 = ssl.PROTOCOL_TLSv1



import functools
import ssl

old_init = ssl.SSLSocket.__init__

@functools.wraps(old_init)
def vsido_gmail_bug(self, *args, **kwargs):
  kwargs['ssl_version'] = ssl.PROTOCOL_TLSv1
  old_init(self, *args, **kwargs)

ssl.SSLSocket.__init__ = vsido_gmail_bug


The first one is a simple one while the second a bit more elegant! One of them should work, Hopefully  ;)

Cheers!!!
You Can't Always Git What You Want

VastOne

Thank you hakerdefo for the attempt... but these all failed too..

:(

VSIDO      VSIDO Change Blog    

    I dev VSIDO

hakerdefo

Hi there VastOne,
Please run the gmail-parser.py script in terminal and post the complete output here.
Cheers!!!
You Can't Always Git What You Want

hakerdefo

And please post the gmail-parser.py script in question as well!
Cheers!!!
You Can't Always Git What You Want

VastOne

python 2 output:

Traceback (most recent call last):
  File "/home/vastone/gmail_parser.py", line 22, in <module>
    maxlen = sys.argv[3]
IndexError: list index out of range


python 3 is a different error but am posting for knowledge:

File "/home/vastone/gmail_parser.py", line 37
    print '${color3} %s new email(s)\n' % (len(atom.entries))
                                      ^
SyntaxError: invalid syntax


gmail_parser.py

## check-gmail.py -- A command line util to check GMail -*- Python -*-
## modified to display mailbox summary for conky

# ======================================================================
# Copyright (C) 2006 Baishampayan Ghose <b.ghose@ubuntu.com>
# Modified 2008 Hunter Loftis <hbloftis@uncc.edu>
# Time-stamp: Mon Jul 31, 2006 20:45+0530
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# ======================================================================

import sys
import urllib             # For BasicHTTPAuthentication
import feedparser         # For parsing the feed
from textwrap import fill

_URL = "https://mail.google.com/gmail/feed/atom"

uname = sys.argv[1]
password = sys.argv[2]
maxlen = sys.argv[3]

urllib.FancyURLopener.prompt_user_passwd = lambda self, host, realm: (uname, password)

def auth():
    '''The method to do HTTPBasicAuthentication'''
    opener = urllib.FancyURLopener()
    f = opener.open(_URL)
    feed = f.read()
    return feed


def readmail(feed, maxlen):
'''Parse the Atom feed and print a summary'''
atom = feedparser.parse(feed)
print '${color3} %s new email(s)\n' % (len(atom.entries))
for i in range(min(len(atom.entries), maxlen)):
print '${color2}%s' % fill(atom.entries[i].title,38)
#uncomment the following line if you want to show the name of the sender
# print '          ${color2}%s' % atom.entries[i].author
if len(atom.entries) > maxlen:
print ' ${color}more...'

if __name__ == "__main__":
    f = auth()  # Do auth and then get the feed
    readmail(f, int(maxlen)) # Let the feed be chewed by feedparser


Run it as

python /home/location_of_file/gmail_parser.py yourusername yourpassword
VSIDO      VSIDO Change Blog    

    I dev VSIDO