kootenpv / yagmail

Send email in Python conveniently for gmail using yagmail
MIT License
2.66k stars 265 forks source link

oauth2 error #103

Closed qmmp123 closed 6 years ago

qmmp123 commented 6 years ago

Hi, I have a problem when try login via oauth2

Traceback (most recent call last):
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/qmmp123/develop/myproject/handler/views.py", line 26, in main
    handle_data(data, saved_file)
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/celery/local.py", line 191, in __call__
    return self._get_current_object()(*a, **kw)
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/celery/app/task.py", line 380, in __call__
    return self.run(*args, **kwargs)
  File "/home/qmmp123/develop/myproject/handler/tasks.py", line 21, in handle_data
    send_result(saved_file)
  File "/home/qmmp123/develop/myproject/handler/tasks.py", line 110, in send_result
    yag = yagmail.SMTP('mygmail@gmail.com', oauth2_file='~/.credentials/gmail-python-quickstart.json')
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/yagmail/sender.py", line 76, in __init__
    self.login_oauth2(oauth2_file)
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/yagmail/sender.py", line 211, in login_oauth2
    auth_string = get_oauth_string(self.user, oauth2_info)
  File "/home/qmmp123/develop/myproject/.venv/lib/python3.6/site-packages/yagmail/oauth2.py", line 96, in get_oauth_string
    access_token, expires_in = refresh_authorization(**oauth2_info)
TypeError: refresh_authorization() got an unexpected keyword argument 'access_token'
qmmp123 commented 6 years ago

I've found solution. Better pass necessary values of dictionary instead all dictionary. access_token, expires_in = refresh_authorization(oauth2_info['client_id'], oauth2_info['client_secret'], oauth2_info['refresh_token']) instead of access_token, expires_in = refresh_authorization(**oauth2_info)