Python:TLS / SSL连接已关闭

时间:2012-10-05 18:38:51

标签: python https amazon-s3

我的代码

conn = __get_s3_connection(s3_values.get('accessKeyId'), s3_values.get('secretAccessKey'))
key = s3_values.get('proposal_key') + proposal_unique_id + s3_values.get('proposal_append_path')
request = urllib2.Request(conn.generate_url(s3_values.get('expires_in'), 'GET', bucket=s3_values.get('bucket'), key=key))
request.add_header('Accept-encoding', 'gzip')
response = urllib2.urlopen(request)

网址看起来像https://production.myorg.s3.amazonaws.com/key/document.xml.gz?Signature=signature%3D&Expires=1349462207&AWSAccessKeyId=accessId

此方法工作正常,直到1小时后,但是当我运行相同的程序时,它会抛出

Traceback (most recent call last):
  File "/Users/hhimanshu/IdeaProjects/analytics/src/utilities/documentReader.py", line 145, in <module>
    main()
  File "/Users/hhimanshu/IdeaProjects/analytics/src/utilities/documentReader.py", line 141, in main
    x = get_proposal_data_from_s3('documentId')
  File "/Users/hhimanshu/IdeaProjects/analytics/src/utilities/documentReader.py", line 54, in get_proposal_data_from_s3
    response = urllib2.urlopen(request)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 392, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 410, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 370, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1194, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1161, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 6] _ssl.c:503: TLS/SSL connection has been closed>

可能是什么原因?我该如何避免这种情况?

1 个答案:

答案 0 :(得分:2)

这是因为间歇性的互联网连接。已自行决定