How to resolve Forbidden 403 error when making a urllib request with POST data in Django using Docker?

I have a three layer Django project that uses Docker. The first container is the front end and does all of the rendering, the second layer deals with logic for what to display on the front end and interacts with the database layer (third) by requesting JSON, and the third container/layer interacts directly with the database.

I have a form in the front end where a user tries to sign up. However, when I make an API call to my second layer using POST and passing the form values, I keep receiving a 403 Forbidden Error. I am using a CSRF token in my form. How can I remove the 403 Forbidden Error?

  • Docker dotnet core nginx proxy 502
  • How to assign specific IP to container and make that accessible outside of VM host?
  • Connecting to SQL Server Express from within Docker Container gives an error occurred evaluating the password
  • Ansible docker_container etc_hosts with variable key
  • How to write compile and make log in Dockerfile?
  • Unable to connect to dockerized postgres on localhost, but remote connection is working
  • Some code in my at the front end level:

    def signup(request):
          #more code
          username = form.cleaned_data["username"] 
          #and some more fields
          data = {"username": username, "password":password, ... "location": location}
          postData = urllib.parse.urlencode(data).encode('utf-8')
             req = urllib.request.Request("url to API in 2nd layer", postData)
          #more code

    Django attempts to execute the try statement, but I am getting a 403 Forbidden Error.

  • Plex using Ansible and Docker
  • Can't access docker containers when there more than 2 containers
  • VMWare VIC (Photon OS + Docker) vs CoreOS + Docker
  • can't pull images from pvt registry with spotify's docker maven plugin
  • Pull image with docker-compose run
  • Docker container migration
  • One Solution collect form web for “How to resolve Forbidden 403 error when making a urllib request with POST data in Django using Docker?”

    You need to allow CORS calls in your 2nd Django project

    pip install django-cors-headers





    Here is the referenced lib. Django-CORS-Headers

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.