这里也有类似的问题 - Cant update email via API - invalid_access error
我在服务器日志中看到:
Started PUT "/u/brodie-16/preferences/avatar/pick.json" for 24.17.99.993 at 2022-09-08 10:28:10 +0000
Processing by UsersController#pick_avatar as JSON
Parameters: {"upload_id"=>13, "type"=>"uploaded", "username"=>"pelican-16", "user"=>{}}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 34ms (Views: 0.3ms | ActiveRecord: 0.0ms | Allocations: 6549)
我正在进行的请求:
import requests
import json
url = "https://blah.blahblah.blah/u/brodie-16/preferences/avatar/pick.json"
payload = json.dumps({
"upload_id": 13,
"type": "uploaded"
})
headers = {
'Api-Key': 'blahblahblahblahhhhh',
'Api-Username': 'system',
}
response = requests.request("PUT", url, headers=headers, json=payload)
print(response.text)
我从 API 收到的响应:
{
"failed": "FAILED"
}
我知道这与负载均衡器/代理无关,因为它甚至在运行 Discourse 的实例本地也无法正常工作。
[root@ip-10-say-whatt-2 discourse]# curl --insecure --location --request PUT 'https://localhost/u/brodie-16/preferences/avatar/pick.json' \
> --header 'Api-Key: blahblah' \
> --header 'Api-Username: system' \
> --header 'Content-Type: application/json' \
> --data-raw '{
> "upload_id": 13,
> "type": "uploaded"
> }'
{"failed":"FAILED"}
最近也有其他人发布了这个问题 - Can't verify CSRF token authenticity while creating topics
有人知道怎么回事吗?