jeremyephron / simplegmail

A simple Gmail API client for applications in Python
MIT License
336 stars 73 forks source link

New install: ipykernel_launcher.py: error: unrecognized arguments #80

Open connorferster opened 2 years ago

connorferster commented 2 years ago

Hi there!

I am excited to try your library. I installed it and followed the instructions for setting up my project, OAuth token, and Gmail API access in the README.

I made sure that I had downloaded the 'client_secret.json' file that Google gave me and stored it in the same directory as my Jupyter notebook.

I then tried running the following:

from simplegmail import Gmail
gmail = Gmail()

And received the following traceback:

usage: ipykernel_launcher.py [--auth_host_name AUTH_HOST_NAME]
                             [--noauth_local_webserver]
                             [--auth_host_port [AUTH_HOST_PORT ...]]
                             [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
ipykernel_launcher.py: error: unrecognized arguments: -f /home/connorferster/.local/share/jupyter/runtime/kernel-0149c95f-ad13-4caa-80d5-dfe1c3b82ebe.json

An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

Is this an error you have seen before and are able to assist with?

siddharthapriya commented 1 year ago

@jeremyephron I am also facing the same issue. Please suggest measures to correct it. I observed some solutions here but not able to figure out how to incorporate them as the package is maintained by you - (a) https://www.pythonfixing.com/2022/01/fixed-how-to-fix-ipykernellauncherpy.html (b) https://stackoverflow.com/questions/48796169/how-to-fix-ipykernel-launcher-py-error-unrecognized-arguments-in-jupyter

Thanks

LucRSquared commented 1 year ago

I'm facing the same issue. Up until recently I was able to use the library in Google Colab provided I had the client_secret.json and gmail_token.json properly passed as arguments to Gmail():

gmail = Gmail(
    client_secret_file=f'{credentials_dir}/client_secret.json',
    creds_file=f'{credentials_dir}/gmail_token.json'
)

But now I'm getting that same issue which seems to be related to the argparser library. I wonder why all of a sudden it's not working anymore.. :/

Here's the full error stack:

---------------------------------------------------------------------------
SystemExit                                Traceback (most recent call last)
[<ipython-input-19-9b6ddb1e1b84>](https://localhost:8080/#) in <module>
      3 
      4 get_ipython().run_line_magic('tb', '')
----> 5 gmail = Gmail(
      6     client_secret_file=f'{credentials_dir}/client_secret.json',
      7     creds_file=f'{credentials_dir}/gmail_token1.json'

5 frames
[/usr/local/lib/python3.8/dist-packages/simplegmail/gmail.py](https://localhost:8080/#) in __init__(self, client_secret_file, creds_file, _creds)
     84                     self.client_secret_file, self._SCOPES
     85                 )
---> 86                 self.creds = tools.run_flow(flow, store)
     87 
     88             self._service = build(

[/usr/local/lib/python3.8/dist-packages/oauth2client/_helpers.py](https://localhost:8080/#) in positional_wrapper(*args, **kwargs)
    131                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
    132                     logger.warning(message)
--> 133             return wrapped(*args, **kwargs)
    134         return positional_wrapper
    135 

[/usr/local/lib/python3.8/dist-packages/oauth2client/tools.py](https://localhost:8080/#) in run_flow(flow, storage, flags, http)
    192     """
    193     if flags is None:
--> 194         flags = argparser.parse_args()
    195     logging.getLogger().setLevel(getattr(logging, flags.logging_level))
    196     if not flags.noauth_local_webserver:

[/usr/lib/python3.8/argparse.py](https://localhost:8080/#) in parse_args(self, args, namespace)
   1781         if argv:
   1782             msg = _('unrecognized arguments: %s')
-> 1783             self.error(msg % ' '.join(argv))
   1784         return args
   1785 

[/usr/lib/python3.8/argparse.py](https://localhost:8080/#) in error(self, message)
   2531         self.print_usage(_sys.stderr)
   2532         args = {'prog': self.prog, 'message': message}
-> 2533         self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

[/usr/lib/python3.8/argparse.py](https://localhost:8080/#) in exit(self, status, message)
   2518         if message:
   2519             self._print_message(message, _sys.stderr)
-> 2520         _sys.exit(status)
   2521 
   2522     def error(self, message):

SystemExit: 2
usage: ipykernel_launcher.py [--auth_host_name AUTH_HOST_NAME]
                             [--noauth_local_webserver]
                             [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
                             [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
ipykernel_launcher.py: error: unrecognized arguments: -f /root/.local/share/jupyter/runtime/kernel-ff84cd7a-2287-44f1-bab7-998f81547fea.json
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2
LucRSquared commented 1 year ago

I fixed my problem. Turns out the app wasn't configured properly and the credentials expired because it wasn't set on published mode but just testing. So the simplegmail library tried to regenerate credentials by opening the browser and going through the process again which it couldn't do from Google Colab.