Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python &引用;“对等端重置连接”;在谷歌上,而不是aws上,指向完全相同的站点_Python_Ssl_Networking_Amazon Ec2_Google Compute Engine - Fatal编程技术网

Python &引用;“对等端重置连接”;在谷歌上,而不是aws上,指向完全相同的站点

Python &引用;“对等端重置连接”;在谷歌上,而不是aws上,指向完全相同的站点,python,ssl,networking,amazon-ec2,google-compute-engine,Python,Ssl,Networking,Amazon Ec2,Google Compute Engine,我有下面的代码,作为测试运行在AWSEC2服务器和谷歌云(GCP)计算引擎上。(我需要让谷歌的EC2退役) Telnet可从AWS和GCP工作,但当我尝试连接时: AWS成功(获取数据) GCP因“对等方重置连接”而失败 正在为测试运行的代码是: import requests, json import datetime as dt epoch_date = int((dt.datetime(2018,2,21) - dt.datetime(1970,1,1)).total_seconds

我有下面的代码,作为测试运行在AWSEC2服务器和谷歌云(GCP)计算引擎上。(我需要让谷歌的EC2退役)

Telnet可从AWS和GCP工作,但当我尝试连接时:

  • AWS成功(获取数据)
  • GCP因“对等方重置连接”而失败
正在为测试运行的代码是:

import requests, json
import datetime as dt

epoch_date = int((dt.datetime(2018,2,21) - dt.datetime(1970,1,1)).total_seconds())
url = 'https://www.zacks.com/includes/classes/z2_class_calendarfunctions_data.php?calltype=eventscal&date={}&type=1'.format(epoch_date)
req = requests.get(url)
data = req.text
print(data[0:100])
我在GCP上得到的例外是:(AWS左,谷歌右)


我想知道这是否指向google服务器上的SSL/握手问题。但我不知道如何解决这个问题。不知道为什么Zacks.com会限制谷歌的IP,但不会限制AWS的IP。AWS和GCP都启用了防火墙。我该怎么解决这个问题呢?或者我还应该探究什么?

“我想知道这是否指向google server上的SSL/握手问题”-鉴于它在读取响应时中止,它必须已成功发送请求,这意味着SSL握手(在发送请求之前)也已成功完成。您如何知道zacks.com已发送响应?GCP拒绝响应的问题也是如此,因此我的python没有得到json响应?“你怎么知道zacks.com发送了响应?”-我不是说zacks.com发送了(HTTP)响应。我是说TLS握手成功了。我得出这个结论是因为代码在
conn.getresponse
中,即它正在尝试读取HTTP响应。由于HTTP响应是在发送请求后读取的,因此它必须已发送请求。由于请求仅在SSL握手成功后发送。可能是由于Python和requests的版本不同,客户端发送的HTTP请求在AWS和GCP之间有所不同,并且服务器喜欢AWS发送的HTTP请求,而不喜欢另一个。也可能是服务器出于某种原因阻止了来自GCP的请求。不幸的是,我无法重现您看到的内容,因此我无法进一步调试它,只能猜测可能的情况。
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 610, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 247, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/home/karunkrishna/.local/lib/python3.5/site-packages/six.py", line 692, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 560, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 379, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)
  File "/usr/lib/python3.5/ssl.py", line 929, in recv_into
    return self.read(nbytes, buffer)
  File "/usr/lib/python3.5/ssl.py", line 791, in read
    return self._sslobj.read(len, buffer)
  File "/usr/lib/python3.5/ssl.py", line 575, in read
    v = self._sslobj.read(len, buffer)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))