0

我的代码

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>

可能是什么原因?我怎样才能避免这种情况?

4

1 回答 1

2

这是因为断断续续的互联网连接。自行解决

于 2012-10-06T16:37:24.613 回答