2016-12-28 120 views
0

您好我在使用python製作HTTP POST請求腳本時遇到了麻煩。這裏是關於我必須達到的目標的描述,但我不知道從哪裏開始。描述是:在python中使用JSON字符串的HTTP POST請求

說明

第一,構造一個JSON字符串象下面這樣:

{ 
    "github_url": "https://gist.github.com/YOUR_ACCOUNT/GIST_ID", 
    "contact_email": "EMAIL" 
} 

然後,使HTTP POST請求到包含JSON字符串作爲一個機構的URL http://WEBSITE部分。

Content-Type: of the request must be "application/json". 

The URL is protected by HTTP Basic Authentication, which is explained on Chapter 2 of RFC2617, so you have to provide an Authorization: header field in your POST request 

For the "userid" of HTTP Basic Authentication, use the same email address you put in the JSON string. 

對於「密碼」,提供一個符合RFC6238 TOTP的10位基於時間的一次性密碼。 您必須閱讀RFC6238(以及勘誤表!)並自行獲取正確的一次性密碼。 TOTP的「時間步長X」是30秒。 「T0」爲0.

使用HMAC-SHA-512作爲散列函數,而不是默認的HMAC-SHA-1

令牌共享密碼是用戶標識後跟ASCII字符串值「CATE399」(不包括雙引號)。

1. For example, if the userid is "[email protected]", the token shared secret is "[email protected]". 

2. For example, if the userid is "[email protected]", the token shared secret is "[email protected]" 

如果你的POST請求成功,服務器將返回HTTP狀態碼200

任何人都可以請一個HTTP POST請求腳本給我嗎?

+0

沒有人會爲您編寫代碼。你應該自己做。您可以要求修復您在代碼中遇到的一些問題,但不要求提供完整的腳本。在提出問題之前,您可能需要檢查此http://stackoverflow.com/help/mcve – Andersson

回答

0

有用於TOTP許多蟒蛇庫,這裏是在這種情況的一個例子https://github.com/pyotp/pyotp

您的代碼如下:
進口pyotp
TOTP = pyotp.TOTP( 「CATE399」)
密碼= totp.now()