New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling DRF API internally within same server with urllib3 not working #3883
Comments
Interesting... It works fine if I starting the server using cookiecutter-django/{{cookiecutter.project_slug}}/compose/local/django/start Lines 9 to 13 in 68f21b6
I'm not sure why it doesn't work in this case. Maybe a protection to avoid circular requests in uvicorn? Taking a step back, would be interesting to see why you need to do internal requests like this in the first place, that seems like a rather uncommon design. Can you find another way around it? If you really have no way around it, I would suggest a few things:
Not sure it's an issue with cookiecutter django at this point, unless there is a config change that fixes it. |
Hey, @browniebroke Thanks for your response. Due to requirements, I have one API which has a huge nested payload and I don't want to use form data on the client side. So I decided to use JSON payload due to nested objects. That's why I created two separate API's for this. One is for uploading the media files and in the second API I am using the media files URL to get those files internally and using them while creating model objects. I can't directly save previous media file URL's in models due to the custom file system design (path should be like /media/instance.id/file-type/unique-file-name). So I thought I'll fetch media files again and save them into models. Finally, I found another workaround for my requirements instead of hitting API again I am getting the file from the previously saved model. media = Model.objects.get( )
new = NewModel.objects.create(file=media.file.open()) |
Assuming the original issue was solved, it will be automatically closed now. |
What happened?
I have one project where I created two API and I am calling one API internally when someone is calling other API.
What should've happened instead?
Without Docker (cookie cutter) it is working fine, but not working in cookie-cutter project.
Additional details
Trying on local machine
Used Docker with cookie cutter
Django function views:-
I added two view so I am calling parent view endpoint from child view.
My Django server hangs after below log for infinite time if I didn't add timeout
url--------------------> http://172.22.0.5:8000/project/parent DEBUG 2022-09-27 15:09:22,223 connectionpool 80 139840035317504 Starting new HTTP connection (1): 172.22.0.5:8000
after adding timeout I am getting
raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='172.22.0.5', port=8000): Max retries exceeded with url: /project/parent (Caused by ReadTimeoutError("HTTPConnectionPool(host='172.22.0.5', port=8000): Read timed out. (read timeout=10)")) INFO: 192.168.1.7:34684 - "POST /project/child/ HTTP/1.1" 500 Internal Server Error
I tried with different hosts but got the same response.
tried hosts are:- localhost, my host system IP, docker container IP
And I can access both endpoints from Postmen without any issue with above hosts
I am able to get response with the same code on local python repl as well as from shell_plus inside different Django container and even the same container python repl.
Version of cookiecutter CLI (get it with
cookiecutter --version
):OS name and version: Ubuntu 20.04
On Linux, run
On Linux and MacOS:
cat ${HOME}/.cookiecutter_replay/cookiecutter-django.json
(Please, take care to remove sensitive information)
}
```
The text was updated successfully, but these errors were encountered: