Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo example_bypass_sni.py run error #137

Closed
qihua opened this issue Oct 9, 2020 · 3 comments
Closed

demo example_bypass_sni.py run error #137

qihua opened this issue Oct 9, 2020 · 3 comments

Comments

@qihua
Copy link

qihua commented Oct 9, 2020

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 444, in wrap_socket
cnx.do_handshake()
File "/usr/local/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1915, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/usr/local/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1639, in _raise_ssl_error
raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (54, 'ECONNRESET')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 849, in validate_conn
conn.connect()
File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 356, in connect
ssl_context=context)
File "/usr/local/lib/python3.7/site-packages/urllib3/util/ssl
.py", line 359, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/local/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 450, in wrap_socket
raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: SysCallError(54, 'ECONNRESET')",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='app-api.pixiv.net.cdn.cloudflare.net.', port=443): Max retries exceeded with url: /auth/token (Caused by SSLError(SSLError("bad handshake: SysCallError(54, 'ECONNRESET')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/jerry/PycharmProjects/pixivpy/pixivpy3/api.py", line 59, in requests_call
**self.requests_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 581, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests_toolbelt/adapters/host_header_ssl.py", line 43, in send
return super(HostHeaderSSLAdapter, self).send(request, **kwargs)
File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='app-api.pixiv.net.cdn.cloudflare.net.', port=443): Max retries exceeded with url: /auth/token (Caused by SSLError(SSLError("bad handshake: SysCallError(54, 'ECONNRESET')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/jerry/PycharmProjects/pixivpy/example_bypass_sni.py", line 37, in
main()
File "/Users/jerry/PycharmProjects/pixivpy/example_bypass_sni.py", line 27, in main
api.login(_USERNAME, _PASSWORD)
File "/Users/jerry/PycharmProjects/pixivpy/pixivpy3/api.py", line 73, in login
return self.auth(username=username, password=password)
File "/Users/jerry/PycharmProjects/pixivpy/pixivpy3/api.py", line 109, in auth
r = self.requests_call('POST', url, headers=headers, data=data)
File "/Users/jerry/PycharmProjects/pixivpy/pixivpy3/api.py", line 64, in requests_call
raise PixivError('requests %s %s error: %s' % (method, url, e))
pixivpy3.utils.PixivError: requests POST https://app-api.pixiv.net.cdn.cloudflare.net./auth/token error: HTTPSConnectionPool(host='app-api.pixiv.net.cdn.cloudflare.net.', port=443): Max retries exceeded with url: /auth/token (Caused by SSLError(SSLError("bad handshake: SysCallError(54, 'ECONNRESET')")))

@upbit
Copy link
Owner

upbit commented Oct 10, 2020

#138 应该是一个问题。看域名是P站指向了 cloudflare.net,导致之前bypass的方法失效了

cloudflare会验证流量来源来防DDoS,但也阻碍了这种爬取方式。

@upbit
Copy link
Owner

upbit commented Oct 11, 2020

Try set a hostname not point to cloudflare, eg:

    api = ByPassSniApi()  # Same as AppPixivAPI, but bypass the GFW
    api.require_appapi_hosts(hostname="public-api.secure.pixiv.net")

See bcceffc

@qihua
Copy link
Author

qihua commented Oct 11, 2020

谢谢大大,可以工作了

@qihua qihua closed this as completed Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants