# Getting \["BAD CSRF"\] when updating topic via API \[python\]

**URL:** https://meta.discourse.org/t/getting-bad-csrf-when-updating-topic-via-api-python/199857
**Category:** Development
**Tags:** rest-api
**Created:** [August 9, 2021, 7:25pm UTC](https://meta.discourse.org/t/getting-bad-csrf-when-updating-topic-via-api-python/199857 "2021-08-09T19:25:01Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![pedroleaoc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pedroleaoc/32/230359_2.png) [@pedroleaoc](https://meta.discourse.org/u/pedroleaoc)
#### Post date: [August 9, 2021, 7:53pm UTC](https://meta.discourse.org/t/getting-bad-csrf-when-updating-topic-via-api-python/199857/3 "2021-08-09T19:53:18Z")

</div>

You are right, that’s something the tool I am using to test the API is doing and it works and that’s a problem on itself apparently:

```python
header1 = CaseInsensitiveDict()
header1["Authorization"] = '{"api-key": "longapikey", "api-username": "myusername"}'

header2 = {"api-key": "longapikey", "api-username": "myusername"}

r = requests.get(url, headers= HEADER)

```

When `HEADER` == header1, it works, when == header2, I get:

```json
{"errors":["You are not permitted to view the requested resource. The API username or key is invalid."],"error_type":"invalid_access"}

```

Thanks for your reply btw!

---

_[View the full topic](https://meta.discourse.org/t/getting-bad-csrf-when-updating-topic-via-api-python/199857)._
