error with signature token when filling a typeform

痴心易碎 提交于 2021-02-11 06:58:19

问题


I'm learning Python and I'm trying to fill a type form using Python requests, however I get this error response:

{"code":"VALIDATION_ERROR","description":"The provided body is malformed.","details":[{"code":"INVALID_PAYLOAD","description":"signature mismatch","in":"BODY","field":".signature"}]}

However, when I put the token.text value manually in data it works. I can't get it working when adding the token programmatically to the payload, even tried with str() and it's not working.

Here is the code:

import requests
import time

epochTime = int(time.time())
token = requests.get("https://mehdikhireddine.typeform.com/app/form/result/token/OcotDC/default")
final = token.text
print(token.text)
data = { "signature": final,
         "form_id": "OcotDC",
         "landed_at": epochTime,""
         "answers": [
        {
            "field": {
                "id": "nDoisfzMsrBP",
                "type": "short_text"
            },
            "type": "text",
            "text": "mehdilemoi"
        },
        {
            "field": {
                "id": "iCW4s6Fc37OL",
                "type": "legal"
            },
            "type": "boolean",
            "boolean": True
        }

    ]
}
r = requests.post("https://mehdikhireddine.typeform.com/app/form/submit/OcotDC", json=data)
print(r.text)

回答1:


This issue arises if you store the epochTime before getting the token from the HTTPS response, presumably because the server then fails to match the signature and time, resulting in "signature mismatch".

You can fix this by taking the current time after the token response has been received, i.e.:

token = requests.get("https://mehdikhireddine.typeform.com/app/form/result/token/OcotDC/default")
epochTime = int(time.time())

Output:

{"message":"success"}

Note that this may still intermittently fail if too much time elapses between getting the response and getting the epochTime.



来源:https://stackoverflow.com/questions/61272853/error-with-signature-token-when-filling-a-typeform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!