Author Topic: gmail-parser.py failure  (Read 3867 times)

VastOne

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
gmail-parser.py failure
« on: November 12, 2016, 10:21:36 PM »
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

Code: [Select]
  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 Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

PackRat

  • Posts: 1879
    • View Profile
Re: gmail-parser.py failure
« Reply #1 on: November 12, 2016, 10:44:19 PM »
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

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #2 on: November 12, 2016, 10:47:04 PM »
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 Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

PackRat

  • Posts: 1879
    • View Profile
Re: gmail-parser.py failure
« Reply #3 on: November 12, 2016, 10:48:07 PM »
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

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #4 on: November 12, 2016, 10:53:46 PM »
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 Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

VastOne

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #5 on: November 12, 2016, 10:57:50 PM »
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 Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

PackRat

  • Posts: 1879
    • View Profile
Re: gmail-parser.py failure
« Reply #6 on: November 12, 2016, 11:24:50 PM »
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

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #7 on: November 12, 2016, 11:26:56 PM »
Same conky on all systems...

Good thought... :D
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

jedi

  • DEFCON 1
  • Posts: 1502
  • Not all those who wander are lost.
    • View Profile
    • NixNut.com
Re: gmail-parser.py failure
« Reply #8 on: November 13, 2016, 03:32:08 AM »
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

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #9 on: November 13, 2016, 03:39:55 AM »
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 Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 520
    • View Profile
    • Looking at Linux through the Windows of Life
Re: gmail-parser.py failure
« Reply #10 on: November 13, 2016, 02:14:51 PM »
Just make sure the following packages are there (they should be, most likely),

Code: [Select]
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,

Code: [Select]
import ssl
ssl.PROTOCOL_SSLv23 = ssl.PROTOCOL_TLSv1

Code: [Select]
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

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #11 on: November 13, 2016, 04:22:32 PM »
Thank you hakerdefo for the attempt... but these all failed too..

 :(

VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

hakerdefo

  • Posts: 520
    • View Profile
    • Looking at Linux through the Windows of Life
Re: gmail-parser.py failure
« Reply #12 on: November 13, 2016, 09:23:43 PM »
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

  • Posts: 520
    • View Profile
    • Looking at Linux through the Windows of Life
Re: gmail-parser.py failure
« Reply #13 on: November 13, 2016, 09:25:02 PM »
And please post the gmail-parser.py script in question as well!
Cheers!!!
You Can't Always Git What You Want

VastOne

  •      v-ger
  • Posts: 3912
    • View Profile
    • VSIDO Community
Re: gmail-parser.py failure
« Reply #14 on: November 13, 2016, 09:30:51 PM »
python 2 output:

Code: [Select]
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:

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

gmail_parser.py

Code: [Select]
## 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

Code: [Select]
python /home/location_of_file/gmail_parser.py yourusername yourpassword
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO