2016-12-16 31 views
1

我有一個python3 Django的網站,證書由letsencryptPython的請求的本地地址拋出SSLError

一切都很好,除了請求本地地址使用python的要求:

response = requests.post('http://127.0.0.1:8100', data=data) 

而且它有很奇怪的行爲:

有時候我200,但supervisorctl restart mywebsite後拋出SSLError

然後我做:

response = requests.post('http://127.0.0.1:8100', data=data, verify=True) 

一切都很好,直到我讓supervisorctl restart mywebsite一個更多的時間,而它拋出SSLError O_O現在用

response = requests.post('http://127.0.0.1:8100', data=data) 

只能所以最終的工作代碼爲:

try: 
    response = requests.post('http://127.0.0.1:8100', data=data, verify=True) 
except: 
    try: 
     response = requests.post('http://127.0.0.1:8100', data=data) 
    except: 
     response = requests.post('http://127.0.0.1:8100', data=data, verify=False) 

而且顯然這不是最好的計劃)

大THX的建議

+0

請在下面檢查我的答案,並且如果有幫助,請將其upvote或mark標記爲已接受。謝謝 –

回答

0

最有可能你的web應用程序發出一個重定向從http://https://。您可以通過使用curl -v查看響應標題來驗證此情況。重定向後,您可能會因爲使用本地主機而不是域名而獲得SSL錯誤:

您無法獲得本地主機的證書;證書頒發機構只能爲公共可見的全球唯一域名頒發證書。本地主機不計數,並且證書頒發機構不允許爲其頒發證書。 - https://community.letsencrypt.org/t/can-i-test-lets-encrypt-client-on-localhost/15627

編輯:

嘗試做的https:// URL與verify=False初始請求。

+0

嗨,對於那個遲到的迴應,我試着https登錄http: response = requests.post('https://127.0.0.1:8100',data = data,verify = True) 它沒有工作,非常長的超時請求 – MaxCore

+0

您是否嘗試過我的上次編輯建議? >嘗試使用verify = False在https:// URL上執行初始請求。 –