socks.py参数应该是整数或类似字节的对象,而不是'str'

问题描述 投票:0回答:1

我在远程服务器(pythonanywhere)上使用pydrive,当我运行代码时,它要求输入验证码,而当我提供代码时,出现以下错误

Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=685978119888-2fbsd3hmbmdjf11l976t1bma0thepekl.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.google
apis.com%2Fauth%2Fdrive&access_type=offline&response_type=code
Enter verification code: 4/wwGmzGdLZlTik2zijZS4fjzAfbt-JvstslPApcT68rcnL2ObgW9EKg0

上方是验证块。输入代码时出现以下错误

Traceback (most recent call last):
File "/home/hedihadi/aw.py", line 18, in
uploadimg("h","h","e")
File "/home/hedihadi/aw.py", line 7, in uploadimg
gauth.CommandLineAuth() # <--
File "/home/hedihadi/.local/lib/python3.7/site-packages/pydrive/auth.py", line 125, in _decorated
self.Auth(code)
File "/home/hedihadi/.local/lib/python3.7/site-packages/pydrive/auth.py", line 495, in Auth
self.Authenticate(code)
File "/home/hedihadi/.local/lib/python3.7/site-packages/pydrive/auth.py", line 508, in Authenticate
self.credentials = self.flow.step2_exchange(code)
File "/usr/lib/python3.7/site-packages/oauth2client/_helpers.py", line 133, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/oauth2client/client.py", line 2054, in step2_exchange
http, self.token_uri, method='POST', body=body, headers=headers)
File "/usr/lib/python3.7/site-packages/oauth2client/transport.py", line 282, in request
connection_type=connection_type)
File "/usr/lib/python3.7/site-packages/httplib2/init.py", line 1957, in request
cachekey,
File "/usr/lib/python3.7/site-packages/httplib2/init.py", line 1622, in _request
conn, request_uri, method, body, headers
File "/usr/lib/python3.7/site-packages/httplib2/init.py", line 1528, in _conn_request
conn.connect()
File "/usr/lib/python3.7/site-packages/httplib2/init.py", line 1309, in connect
sock.connect((self.host, self.port))
File "/usr/lib/python3.7/site-packages/socks.py", line 406, in connect
self.__negotiatehttp(destpair[0],destpair[1])
File "/usr/lib/python3.7/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

这是我的aw.py文件,我在其中运行代码并得到错误

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

def uploadimg(kart, band, fraction):
gauth = GoogleAuth()
gauth.CommandLineAuth() # <--
drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'title': "lqi"+fraction+"bandi"+band+"karti"+kart})
file1.SetContentFile("hi.jpg")
file1.Upload()

file3 = drive.CreateFile({'id': file1['id']})
uploadimg("h","h","e")
python google-oauth socks pydrive
1个回答
2
投票

您使用的是免费帐户,因此需要将PyDrive配置为使用PythonAnywhere代理。有关如何执行此操作的详细信息,请参见PyDrive Github上的问题;有关代理的详细信息,请参见PythonAnywhere帮助页面。

© www.soinside.com 2019 - 2024. All rights reserved.