Responses is a Python library for mocking out the Python Requests library.
Questions tagged [python-responses]
46 questions
5
votes
1 answer
python responses - Not all requests have been executed
I'm trying test case to mock a api call and using python responses to mock the api call.
Below is my mock,
with responses.RequestsMock() as rsps:
url_re = re.compile(r'.*udemy.com/api-2.0/courses.*')
url_re =…

user1050619
- 19,822
- 85
- 237
- 413
5
votes
1 answer
How to get JSON.loads() output in dictionary type but not string type using PYTHON
When I make use of JSON.dump() I am getting below JSON format
Dumps data"b'{\"AutomaticReadabilityIndex\":2.7999999999999994,\"AgeLevel\":[\" 11 to 12\"],\"Statement\":[\"Nice. Your grade is about…

Madhu
- 79
- 1
- 5
3
votes
1 answer
How can I de-duplicate responses for pytest?
The responses library provides mocks for requests. In my case, it looks typically like this:
import responses
@responses.activate
def test_foo():
# Add mocks for service A
responses.add(responses.POST, 'http://service-A/foo', json={'bar':…

Martin Thoma
- 124,992
- 159
- 614
- 958
2
votes
1 answer
Python: Put request to rest api sends Bad request 400 error
I am sending a Put request to Rest Api to update user information based on username, and it gives following error
400 Bad Request
Bad Request
The browser (or proxy)…

Sara
- 181
- 1
- 3
- 16
2
votes
2 answers
python mock responses with url parameters
I have this URL and im successfully able to call this responses.
https://www.udemy.com/api-2.0/courses/?page=1&page_size=5
Now, I'm trying to mock the responses and testing my api but mock throws a ConnectionError
with responses.RequestsMock() as…

user1050619
- 19,822
- 85
- 237
- 413
2
votes
1 answer
Python request get and put data in increments
first time post, long time reader. I am very new to coding and just trying to teach myself using the net.
I have some code in python im having trouble with and would love some help. I have 2 python scripts that basically read data from my AC unit…

akkaria
- 21
- 1
1
vote
1 answer
Problem with exception handling using Python requests module
The following part of my code is supposed to do exception handling during HTTP requests.
app.py
class Get:
def __init__(self, url):
self.url = url
def get(self):
waitingFactor = 1
for i in range(0,5): #retries if a…

Bornak
- 65
- 1
- 6
1
vote
1 answer
Python request gives 404 response, but I get 200 when I run the code from local server
I have used python requests before. However, now I am facing a 404 problem on this specific site Jiomart.com.
When I try to sent requests from my local server, it gives me 200 as the response. After when I completed the project and deployed it on…

AdnanKattekaden
- 109
- 6
1
vote
0 answers
Mocking query_params using responses and pytest
I would like some help to mock a query_param using responses and pytest.
I have this view:
@api_view(["GET"])
@csrf_exempt
@permission_classes((AllowAny,))
def get_code_and_extra(request):
code = request.GET.get("code", "")
extra =…

Joey Fran
- 598
- 2
- 24
1
vote
1 answer
How to allow non mocked endpoints when using responses library
In Python it's really common to use requests library to make your HTTP requests.
import requests
r = requests.get('http://google.com')
print(f"Code: {r.status_code}\nText head: {r.text[:100]}")
>>> Code: 200
>>> Text head:

Btc Sources
- 1,912
- 2
- 30
- 58
1
vote
1 answer
`responses` with `requests` retry handling
I'm attempting to implement/test request retrying within my module - below is a scratch which has the base functionality of what I'm trying to accomplish.
import requests
from requests.adapters import HTTPAdapter
from…

Constantly Confused
- 595
- 4
- 10
- 24
1
vote
1 answer
Downloading excel file from url in pandas (post authentication)
I am facing a strange problem, I dont know much about for my lack of knowledge of html. I want to download an excel file post login from a website.
The file_url is:
file_url="https://xyz.xyz.com/portal/workspace/IN AWP ABRL/Reports & Analysis…

Ankit Goel
- 360
- 1
- 5
- 18
1
vote
0 answers
How to display raw sql query count value in django rest api
The Group by count value is not showing rest api call but group by working perfectly
This is my views.py file
class TestList(generics.ListAPIView):
queryset = Test.objects.raw('SELECT 1 as id ,v1 ,COUNT(*) FROM posts_test GROUP BY v1 order by…

Boxer Robert
- 1,169
- 2
- 8
- 14
1
vote
1 answer
Python responses module is erratic with multi-threading in Linux
I am trying to use the responses module to mock an HTTP server and I have the feeling it is broken when calls requests are multi-threaded.
Consider the following:
import json
import responses
import requests
import threading
try:
import…

wecx
- 302
- 2
- 10
1
vote
2 answers
Adding unnecessary character when writing to a file from "requests" module in python
I have a text file consisting of URL per line as follows:
https://www.google.com
https://www.facebook.com
https://www.gmail.com
I use the following script:
import requests
add = open("manual_list.txt","r")
for a in add:
response =…

user9371654
- 2,160
- 16
- 45
- 78