How to post a django request to external server

后端 未结 2 637
遥遥无期
遥遥无期 2021-01-14 19:40

Hi so I have this method in django views to post the file to a different server. I get an HTTP 415 error complaining about the media type of the request. I have debugged the

相关标签:
2条回答
  • 2021-01-14 20:04

    If you look at the documentation of requests it says about the data keyword:

    data – (optional) Dictionary, bytes, or file-like object to send in the body of the Request.

    Django's request object is an instance of HttpRequest.You should try to put the necessary data in a dictionary and pass it to post().

    0 讨论(0)
  • 2021-01-14 20:11

    Do this:

    r = requests.post('http://localhost:9090/validate', data=request.POST)
    

    You are passing a full django.http.HttpRequest object to requests.post, when you only need its post data.

    0 讨论(0)
提交回复
热议问题