2012-10-05 26 views
0

我的代碼的Python:TLS/SSL連接已關閉

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) 

的URL看起來像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> 

可能是什麼原因?我怎樣才能避免這種情況?

回答

2

這是因爲間歇性的互聯網連接。解決它自己

+0

你可以接受你自己的答案,順便說一句 – 9000

+0

我試過了,所以說你必須等待24小時,我會明天去做 – daydreamer

相關問題