レンタルサーバー上でpythonを実行し、twitterの情報をjsonで取得するためのコードを作成しています。
PC上(Windows10)からアクセスする際は問題なくデータ取得できるのですが、
レンタルサーバー上で実行すると、接続が切られてしまい、困っております。
レンタルサーバー上での発現より、SSL関係もしくは、twitter APIを利用する上での処理があるのか
と思っているのですが、通信関係は知識が乏しく、何を確認してどのような処理をすればいいかもわからなかったため、こちらに投稿させていただきました。
有識者の方、ご助言いただけますと幸いです。
よろしくお願いいたします。
言語:python3.4
サーバー:さくらレンタルサーバー(スタンダード)
#該当コード:
import json
from requests_oauthlib import OAuth1Session
twitter=OAuth1Session(API_KEY, API_SECRET_KEY, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
url = 'https://api.twitter.com/1.1/search/tweets.json'
keyword = 'Items'
params = {'q' : keyword, 'count' : 40}
req = twitter.get(url, params = params)
#以下、エラーメッセージ:
Traceback (most recent call last):
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connectionpool.py", line 994, in validate_conn
conn.connect()
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connection.py", line 394, in connect
ssl_context=context,
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/util/ssl.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/test_Dir/local/python/lib/python3.4/ssl.py", line 365, in wrap_socket
_context=self)
File "/home/test_Dir/local/python/lib/python3.4/ssl.py", line 583, in init
self.do_handshake()
File "/home/test_Dir/local/python/lib/python3.4/ssl.py", line 810, in do_handshake
self._sslobj.do_handshake()
ConnectionResetError: [Errno 54] Connection reset by peer
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/util/retry.py", line 400, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/packages/six.py", line 734, in reraise
raise value.with_traceback(tb)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connectionpool.py", line 994, in validate_conn
conn.connect()
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/connection.py", line 394, in connect
ssl_context=context,
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/urllib3/util/ssl.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/test_Dir/local/python/lib/python3.4/ssl.py", line 365, in wrap_socket
_context=self)
File "/home/test_Dir/local/python/lib/python3.4/ssl.py", line 583, in init
self.do_handshake()
File "/home/test_Dir/local/python/lib/python3.4/ssl.py", line 810, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tweet_read_test_2.py", line 49, in <module>
req = twitter.get(url, params = params)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/test_Dir/www/wp/wp-content/uploads/python_code/../py_vendor/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))
あなたの回答
tips
プレビュー