Headers aren't added to response
See original GitHub issueAhoi,
I’m trying to add headers to a response but can’t figure out why it doesn’t work. I tried these ways:
url = 'https://example.com/?cursor='
resp_body = [{'foo': 'bar'}, ]
responses.add(
responses.Response(
method='GET',
url=url,
json=resp_body,
status=200,
headers={
'Link': f'<{ url }>; rel="first", <{ url }next_cursor>; rel="next"'
},
content_type='application/json'
)
)
responses.add(
responses.GET,
url=f'{ url }next_cursor',
json=resp_body,
adding_headers={
'Link': f'<{ url }>; rel="first", <{ url }prev_cursor>; rel="prev"'
},
status=200
)
In both cases the response returned in the code has only 1 header which is {'Content-Type': 'application/json'}
. Am I doing something wrong?
I stepped through the responses code with a debugger and everything seems to work fine. The Response object gets created with the right headers but when the requests module is called it doesn’t get them back.
here are my versions:
- Python: 3.8.3
- pytest: 5.4.3
- requests: 2.23.0
- responses: 0.10.14
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Headers not showing in fetch response - Stack Overflow
The Header object is not empty. It is just not a regular object so it doesn't have its contents as properties on its...
Read more >Request headers and responses - App Engine - Google Cloud
Headers removed from incoming requests; App Engine-specific headers. Request responses. Headers removed; Headers added or replaced; Response headers set in ...
Read more >HTTP headers - MDN Web Docs - Mozilla
Response headers hold additional information about the response, like its location or about the server providing it. Representation headers ...
Read more >How to troubleshoot the error "Failed to process response ...
The error is correct, the service did not receive any response headers or data. The key to help confirm this is to increase...
Read more >HTTP/1.1: Status Code Definitions
The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields. 10.2.6...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh man… I’m should stop drinking and coding that late. The whole thing didn’t work because I got a one off in my tests. I was looking at the wrong one the whole time. Sorry to bother you. Everything is fine.
I tried everything I found. I also use
headers
exactly like you do but they are not in the response. If you look at my example above, I’m usingheaders
. I also tried to use the second example but withheaders
instead ofadding_headers
but it gives me the same result.I just tried to build a smaller example and that worked:
Now I need to find out why it doesn’t in the real thing.