winerror 10054谷歌日历

2024-05-29 04:18:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个脚本,可以将事件添加到我的日历中,直到今天早上都可以正常工作。我没有做任何改变,但现在不行了。你知道吗

这是我的密码:

from __future__ import print_function
import httplib2
import os
import sys

from apiclient import discovery
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage

from subprocess import Popen

import datetime



# If modifying these scopes, delete your previously saved credentials
# at ~/.credentials/calendar-python-quickstart.json
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'Google Calendar API Python Quickstart'


def get_credentials():
    """Gets valid user credentials from storage.

    If nothing has been stored, or if the stored credentials are invalid,
    the OAuth2 flow is completed to obtain the new credentials.

    Returns:
        Credentials, the obtained credential.
    """
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'calendar-python-quickstart.json')

    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials

def main():
    """Shows basic usage of the Google Calendar API.

    Creates a Google Calendar API service object and outputs a list of the next
    10 events on the user's calendar.
    """
    try:
        if(len(sys.argv) < 2):
            print('No name was provided.')
            input()
            exit()

        credentials = get_credentials()
        http = credentials.authorize(httplib2.Http())
        service = discovery.build('calendar', 'v3', http=http)


        event = {
            'summary': 'Teststop ' + " ".join(sys.argv[1:]),
            'start': {
            'date': str(datetime.date.today() + datetime.timedelta(days=14)),
            'timeZone': 'Europe/Stockholm',
            },
            'end': {
            'date': str(datetime.date.today() + datetime.timedelta(days=14)),
            'timeZone': 'Europe/Stockholm',
            },
        }

        event = service.events().insert(calendarId='CENSORED@group.calendar.google.com', body=event).execute()
        print ('Event created: %s' % (event.get('htmlLink')))
        p = Popen([r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe', r'https://calendar.google.com/calendar/render#main_7%7Cmonth' ], stdin=None, stdout=None, stderr=None)
        exit()
    except Exception as e:
        traceback.print_exc()
        print(str(e))
        input()

if __name__ == '__main__':
    main()

这是我得到的结果:

C:\Users\jhh\executor\scripts\google calendar>py addEvent.py test
Traceback (most recent call last):
  File "addEvent.py", line 63, in main
    service = discovery.build('calendar', 'v3', http=http)
  File "C:\Python\lib\site-packages\oauth2client\_helpers.py", line 133, in posi
tional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Python\lib\site-packages\googleapiclient\discovery.py", line 229, in
build
    requested_url, discovery_http, cache_discovery, cache)
  File "C:\Python\lib\site-packages\googleapiclient\discovery.py", line 276, in
_retrieve_discovery_doc
    resp, content = http.request(actual_url)
  File "C:\Python\lib\site-packages\oauth2client\transport.py", line 175, in new
_request
    redirections, connection_type)
  File "C:\Python\lib\site-packages\oauth2client\transport.py", line 282, in req
uest
    connection_type=connection_type)
  File "C:\Python\lib\site-packages\httplib2\__init__.py", line 1322, in request

    (response, content) = self._request(conn, authority, uri, request_uri, metho
d, body, headers, redirections, cachekey)
  File "C:\Python\lib\site-packages\httplib2\__init__.py", line 1072, in _reques
t
    (response, content) = self._conn_request(conn, request_uri, method, body, he
aders)
  File "C:\Python\lib\site-packages\httplib2\__init__.py", line 995, in _conn_re
quest
    conn.connect()
  File "C:\Python\lib\http\client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "C:\Python\lib\ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "C:\Python\lib\ssl.py", line 814, in __init__
    self.do_handshake()
  File "C:\Python\lib\ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "C:\Python\lib\ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "addEvent.py", line 88, in <module>
    main()
  File "addEvent.py", line 83, in main
    traceback.print_exc()
NameError: name 'traceback' is not defined

我不知道怎么解决这个问题。有什么想法吗?你知道吗


Tags: theinfrompyimporthttplibpackages

热门问题