Django returns 403 error when sending a POST request

后端 未结 7 2094
名媛妹妹
名媛妹妹 2021-01-31 08:27

when I\'m using following Python code to send a POST request to my Django website I\'m getting 403: Forbidden error.

url = \'http://www.sub.domain.com/\'
values          


        
7条回答
  •  孤城傲影
    2021-01-31 08:41

    I got this error when an authentication Token was expired or when no Token was sent with the request. Using a renewed token fixed the problem.

    curl -X POST -H "Authorization: Token mytoken" -d "name=myname&age=0" 127.0.0.1:8000/myapi/
    

    or

    curl -X POST -H "Authorization: JWT mytoken" -d "name=myname&age=0" 127.0.0.1:8000/myapi/
    

    depending on Token type.

提交回复
热议问题