Closed tonny0812 closed 7 years ago
hi,请问您用的是哪个版本的?看上去不应该是这个输出 https://github.com/ly0/baidupcsapi/blob/master/baidupcsapi/api.py#L46
或者可以发一下您的 login.py
?
使用pip install baidupcsapi 下载的模块
//login.py from baidupcsapi import PCS pcs = PCS('***','***') print pcs.quota().content print pcs.list_files('/').content
我使用的账户是通过手机以及邮箱验证的,
pypi上的很久没更新了,你用github上的试试?
python3 下运行。
File "D:\Python\Python35-32\lib\site-packages\baidupcsapi-0.9.0-py3.5.egg\baid
upcsapi\api.py", line 58, in default_captcha_handler
subprocess.call([filename.decode('utf8').encode('cp936')], shell=True)
AttributeError: 'str' object has no attribute 'decode'
Python2
File "E:\share\del\python2\lib\site-packages\baidupcsapi-0.9.0-py2.7.egg\baidu
pcsapi\api.py", line 15, in <module>
from urllib import parse as urlparse
ImportError: cannot import name parse
@wgf4242 已经修复 :)
Python3
from baidupcsapi import PCS
pcs = PCS('xxxxxx','yyyyy'')
print(pcs.quota().content)
print(pcs.list_files('/').content)
错误:
Traceback (most recent call last):
File "E:\share\del\bat_test\tes.py", line 2, in <module>
pcs = PCS('xxxxxx','yyyyy'')
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 492, in __init__
verify_func=verify_callback)
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 169, in __init__
self._initiate()
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 228, in _initiate
self._login()
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 322, in _login
captcha = self._get_captcha(code_string)
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 267, in _get_captcha
"https://passport.baidu.com/cgi-bin/genimage?" + code_string.decode('utf-8'))
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 58, in default_captcha_handler
subprocess.call([filename.encode('cp936')], shell=True)
File "d:\Python\lib\subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "d:\Python\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "d:\Python\lib\subprocess.py", line 966, in _execute_child
args = list2cmdline(args)
File "d:\Python\lib\subprocess.py", line 461, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: a bytes-like object is required, not 'str'
filename.encode('cp936')改成filename了,重新运行后提示 C:\Users\ADMINI~1\AppData\Local\Temp\tmp6tswqff7.png The process cannot access the file because it is being used by another process. Input verify code >
不大清楚windows下发生了什么 可以试试手工打开 C:\Users\ADMINI~1\AppData\Local\Temp\tmp6tswqff7.png
打不开的。不知道被什么东西锁定了。可能在tempfile里windows不这么写吧。
我改了一下
filename = 'E:/share/temp.png'
with open(filename,'wb') as f:
f.write(data)
然后验证码是能输入了。我把上传文件的进度条实现范例复制进去又找不到progressbar了。这是python自带的模块么。
Q1: ModuleNotFoundError: No module named 'progressbar' Q2: 每次都要输入验证码么。能不能保存Cookie之类的。每次输入不能自动化使用。
你可以传入验证码处理的函数的, 初始化PCS类的时候传入captcha_callback参数即可
A1: README里的demo的progressbar是需要安装的, 可以不用. A2: 代码上是实现了cookie的存取的, 难道不work吗? (https://github.com/ly0/baidupcsapi/blob/master/baidupcsapi/api.py#L238)
我看了下python3下应该是装progress2.安装完了在win下和centos下运行还是出错 (前面提到的锁定问题在Linux系统不存在,应该是tempfile在不同系统下写入方法的有点问题.)
N/A% |> | ETA: --:--:--
14% |> | ETA: 0:00:00
19% |> | ETA: 0:00:00Traceback (most recent call last):
File "d:\Python\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "d:\Python\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "d:\Python\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "d:\Python\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "d:\Python\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "d:\Python\lib\http\client.py", line 1065, in _send_output
self.send(chunk)
File "d:\Python\lib\http\client.py", line 986, in send
self.sock.sendall(data)
File "d:\Python\lib\ssl.py", line 965, in sendall
v = self.send(data[count:])
File "d:\Python\lib\ssl.py", line 935, in send
return self._sslobj.write(data)
File "d:\Python\lib\ssl.py", line 636, in write
return self._sslobj.write(data)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\Python\lib\site-packages\requests-2.18.4-py3.6.egg\requests\adapters.py", line 440, in send
timeout=timeout
File "d:\Python\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "d:\Python\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\util\retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File "d:\Python\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\packages\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "d:\Python\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "d:\Python\lib\site-packages\urllib3-1.22-py3.6.egg\urllib3\connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "d:\Python\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "d:\Python\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "d:\Python\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "d:\Python\lib\http\client.py", line 1065, in _send_output
self.send(chunk)
File "d:\Python\lib\http\client.py", line 986, in send
self.sock.sendall(data)
File "d:\Python\lib\ssl.py", line 965, in sendall
v = self.send(data[count:])
File "d:\Python\lib\ssl.py", line 935, in send
return self._sslobj.write(data)
File "d:\Python\lib\ssl.py", line 636, in write
return self._sslobj.write(data)
ret = pcs.upload('/',test_file,'x1.dwg',callback=ProgressBar())
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 606, in upload
files=files, callback=callback, **kwargs)
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 136, in wrapper
ret = func(*args, **kwargs)
File "d:\Python\lib\site-packages\baidupcsapi-0.9.1-py3.6.egg\baidupcsapi\api.py", line 470, in _request
api, data=body, verify=False, headers=headers, **kwargs)
File "d:\Python\lib\site-packages\requests-2.18.4-py3.6.egg\requests\sessions.py", line 555, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "d:\Python\lib\site-packages\requests-2.18.4-py3.6.egg\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "d:\Python\lib\site-packages\requests-2.18.4-py3.6.egg\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "d:\Python\lib\site-packages\requests-2.18.4-py3.6.egg\requests\adapters.py", line 490, in send
raise ConnectionError(err, request=request)
[Finished in 2.0s]
[root1@CentOS_68 Downloads]$ python3 xtes1.py
14% |> | ETA: 0:00:00Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/urllib3-1.22-py3.5.egg/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.5/site-packages/urllib3-1.22-py3.5.egg/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.5/http/client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "/usr/local/lib/python3.5/http/client.py", line 1128, in _send_request
self.endheaders(body)
File "/usr/local/lib/python3.5/http/client.py", line 1079, in endheaders
self._send_output(message_body)
File "/usr/local/lib/python3.5/http/client.py", line 913, in _send_output
self.send(message_body)
File "/usr/local/lib/python3.5/http/client.py", line 882, in send
self.sock.sendall(datablock)
File "/usr/local/lib/python3.5/ssl.py", line 886, in sendall
v = self.send(data[count:])
File "/usr/local/lib/python3.5/ssl.py", line 856, in send
return self._sslobj.write(data)
File "/usr/local/lib/python3.5/ssl.py", line 581, in write
return self._sslobj.write(data)
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/requests-2.18.4-py3.5.egg/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/local/lib/python3.5/site-packages/urllib3-1.22-py3.5.egg/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.5/site-packages/urllib3-1.22-py3.5.egg/urllib3/util/retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/local/lib/python3.5/site-packages/urllib3-1.22-py3.5.egg/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/site-packages/urllib3-1.22-py3.5.egg/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.5/site-packages/urllib3-1.22-py3.5.egg/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/lib/python3.5/http/client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "/usr/local/lib/python3.5/http/client.py", line 1128, in _send_request
self.endheaders(body)
File "/usr/local/lib/python3.5/http/client.py", line 1079, in endheaders
self._send_output(message_body)
File "/usr/local/lib/python3.5/http/client.py", line 913, in _send_output
self.send(message_body)
File "/usr/local/lib/python3.5/http/client.py", line 882, in send
self.sock.sendall(datablock)
File "/usr/local/lib/python3.5/ssl.py", line 886, in sendall
v = self.send(data[count:])
File "/usr/local/lib/python3.5/ssl.py", line 856, in send
return self._sslobj.write(data)
File "/usr/local/lib/python3.5/ssl.py", line 581, in write
return self._sslobj.write(data)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "xtes1.py", line 22, in <module>
ret = pcs.upload('/',test_file,'x1.dwg',callback=ProgressBar())
File "/usr/local/lib/python3.5/site-packages/baidupcsapi-0.9.1-py3.5.egg/baidupcsapi/api.py", line 596, in upload
files=files, callback=callback, **kwargs)
File "/usr/local/lib/python3.5/site-packages/baidupcsapi-0.9.1-py3.5.egg/baidupcsapi/api.py", line 126, in wrapper
ret = func(*args, **kwargs)
File "/usr/local/lib/python3.5/site-packages/baidupcsapi-0.9.1-py3.5.egg/baidupcsapi/api.py", line 460, in _request
api, data=body, verify=False, headers=headers, **kwargs)
File "/usr/local/lib/python3.5/site-packages/requests-2.18.4-py3.5.egg/requests/sessions.py", line 555, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.5/site-packages/requests-2.18.4-py3.5.egg/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.5/site-packages/requests-2.18.4-py3.5.egg/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.5/site-packages/requests-2.18.4-py3.5.egg/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
Connection reset by peer
你这个,是网络问题吧?
尝试使用登录demo,提示需要输入验证码信息,但是输入之后又提示输入