本文介绍了Google Sheets API在PythonAnywhere上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 PythonAnywhere 上运行的 Flask Web应用,它使用了 Google Sheets API .在开发过程中,一切正常,但是在PythonAnywhere上的初学者帐户上部署到生产环境时,出现了以下错误:

I have a Flask web app running on PythonAnywhere and it uses the Google Sheets API. During development, everything went well, but when deployed to production on a Beginner Account on PythonAnywhere, there has been this error:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.8/site-packages/flask/app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/diyaassessments/dal_assessments/main.py", line 736, in new_test
    test_data = create_new_test_sheet(flask.session['username'])
  File "/home/diyaassessments/dal_assessments/main.py", line 214, in create_new_test_sheet
    sheet_id = sheets_api.create_sheet(test_id, gauth.load_credentials())
  File "/home/diyaassessments/dal_assessments/sheets_api.py", line 50, in create_sheet
    service = build('sheets', 'v4', credentials=credentials)
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/googleapiclient/discovery.py", line 270, in build
    content = _retrieve_discovery_doc(
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/googleapiclient/discovery.py", line 376, in _retrieve_discovery_doc
    resp, content = req.execute(num_retries=num_retries)
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 134, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/googleapiclient/http.py", line 900, in execute
    resp, content = _retry_request(
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/googleapiclient/http.py", line 177, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/httplib2/__init__.py", line 1985, in request
    (response, content) = self._request(
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/httplib2/__init__.py", line 1650, in _request
    (response, content) = self._conn_request(
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/httplib2/__init__.py", line 1557, in _conn_request
    conn.connect()
  File "/home/diyaassessments/.local/lib/python3.8/site-packages/httplib2/__init__.py", line 1324, in connect
    sock.connect((self.host, self.port))
  File "/usr/lib/python3.8/site-packages/socks.py", line 406, in connect
    self.__negotiatehttp(destpair[0],destpair[1])
  File "/usr/lib/python3.8/site-packages/socks.py", line 357, in __negotiatehttp
    while resp.find("\r\n\r\n")==-1:
TypeError: argument should be integer or bytes-like object, not 'str'

我从未见过这种错误.是否因为PythonAnywhere阻止了对大多数外部站点的请求而发生?还是它是代码中的错误(尽管在开发过程中完美地起作用了)?
请帮帮我.
谢谢.

I have never seen this kind of error. Did it occur because PythonAnywhere blocks requests to most external sites? Or is it a bug in the code (it worked perfectly during development though)?
Please help me.
Thank you.

推荐答案

根据使用 pip3.8 install --user --force-reinstall PySocks 升级PySocs应该会有所帮助.

According to that upgrade of PySocs with pip3.8 install --user --force-reinstall PySocks should help.

这篇关于Google Sheets API在PythonAnywhere上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 00:02