Why is the request not sending data?


Baek Seung Hyun

I just made the server.

The server returns raw data. So when I use Restlet Client in Chrome Extension to Server I can return json post data.

However, the Python Requests module does not return. I do requestsn't think data is sent.

Python 3.6.8 requests 2.21.0 PHP 7

In PHP:

<?php
print_r($_POST);
?>

In Python:

    try:
        task = self.q.get_nowait()
        # json_data = json.dumps(task)
        if 'picture' in task['data']:
            filename = task['data']['picture']
        else:
            filename = ''

        try:
            task['uuid'] = self.uuid
            if filename == '':
                url = 'http://server_domin/upload_nopic.php'
                data = json.dumps(task)
                print('task: ' + data)
                r = requests.post(url, data=data)
                print("Response: %s" % r.json())
            else:
                url = 'http://server_domin/upload.php'
                files = {'file': open('./images/' + filename, 'rb')}
                print('task: ' + json.dumps(task))
                r = requests.post(url, files=files, data=json.dumps(task))
                print("Response: %s" % r.json())

            # print("Response: %s" % str(r.text()))

        except Exception as ex:
            print("Upload Failure. ", filename, ex)
            traceback.print_stack()
            traceback.print_exc()

    except queues.QueueEmpty:
        pass

I checked the data (variables) before sending and the response after sending. The data is saved normally, but the response received empty data.

in the variable data:

{
  "data": {
    "utc": 1563862224,
    "accel": {
      "ax": -2.3630770385742186,
      "ay": 6.636727001953124,
      "az": 6.009446166992187
    },
    "gyro": {
      "gx": -4.137404580152672,
      "gy": -0.1297709923664122,
      "gz": 0.2366412213740458
    },
    "angle": {
      "ax": -14.785298705742603,
      "ay": 45.78478003457668,
      "az": 49.535035853061935
    },
    "temp": 26.459411764705884
  },
  "uuid": "ac2bbe96-5c2d-b960-6b88-40693bfb6a39"
}

in requests.text():

'' or Array()
Ivan Vinogradov

The remote server may require JSON as input.

Since you use

data = json.dumps(task)
requests.post(url, data=data)

and

requests.post(url, files=files, data=json.dumps(task))

If you don't set Content-Type: application/jsonthe header, your HTTP request may not be understood by the remote server.


When you want to send JSON, use json=datainstead of data=data. This will set the appropriate Content-Typeautomatic for you.

example:

data = {
    "uuid": "ac2bbe96-5c2d-b960-6b88-40693bfb6a39",
    "utc": 1563862224
    # ... other data
}
r = requests.post(url, json=data)
print(r.status_code, r.text)  # it is always a good idea to check response HTTP status code

Related


Why is the request not sending data?

Baek Seung Hyun I just made the server. The server returns raw data. So when I use Restlet Client in Chrome Extension to Server I can return json post data. However, the Python Requests module does not return. I do requestsn't think data is sent. Python 3.6.8

Why is the request not sending data?

Baek Seung Hyun I just made the server. The server returns raw data. So when I use Restlet Client in Chrome Extension to Server I can return json post data. However, the Python Requests module does not return. I do requestsn't think data is sent. Python 3.6.8

why jquery ajax is not sending data in get request

cdm014 I'm setting up a page where our staff can view a list of items that should be on the shelf and then confirm if those items are there, or raise an alert if something goes wrong. I'm trying to create a function for each case (item exists, item doesn't exi

Why is sending HTTP request invalid?

Elam V I have implemented the code below to send the HTTP request to the server, but for some reason it is not working (no entry on fiddler) Can anyone help? [EDIT] I added error handling to the code ; Script generated by the Inno Setup Script Wizard. ; SEE TH

Why is sending HTTP request invalid?

Elam V I have implemented the code below to send the HTTP request to the server, but for some reason it is not working (no entry on fiddler) Can anyone help? [EDIT] I added error handling to the code ; Script generated by the Inno Setup Script Wizard. ; SEE TH

POST request not sending data - fixed

t00n I've been programming in Android Studio for a short amount of time and have been trying to send JSON to an IIS server in a few different ways (Retrofit2, Volley, HttpClient...) but my IIS APP is not getting it right New rows are not introduced in Mysql BB

Error sending POST request with data

beginner I'm trying to create a program that will create an account on this site: https://www.kostkuj.cz/register My main problem is that I don't really know how it works, so I've rebuilt one according to my requirements project. I also tried sending a request

POST request not sending data - fixed

t00n I've been programming in Android Studio for a short amount of time and have been trying to send JSON to an IIS server in a few different ways (Retrofit2, Volley, HttpClient...) but my IIS APP is not getting it right New rows are not introduced in Mysql BB

Error sending POST request with data

beginner I'm trying to create a program that will create an account on this site: https://www.kostkuj.cz/register My main problem is that I don't really know how it works, so I've rebuilt one according to my requirements project. I also tried sending a request

Error sending POST request with data

beginner I'm trying to create a program that will create an account on this site: https://www.kostkuj.cz/register My main problem is that I don't really know how it works, so I've rebuilt one according to my requirements project. I also tried sending a request

Rectangular DELETE request, sending data in the body

Sergey Tyupaev I am using restangular to send DELETE request. I send some data in the request and add the data to the query string. But I want to use body instead of URI. I found this question on stackoverflow . This problem can be solved by using methods , Mg

Objective C post request not sending data

ios development good day. I am trying to send simple post data to the server. This is my code. -(void)makeRequest:(NSString*)stringParameters{ NSError *error; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfigu

$http.get not sending data in request body

winner While using angular v1.3.1, I'm having the following problem trying to implement a facade for making http requests to a REST+JSON interface in the backend of a web application. I get something like this in the code: findSomething(value: number): ng.IPro

Node JS request module not sending form data

Asad Zeynalov I am using the "requests" module in node js to make a post request like this: request.post({url: 'http://localhost:4004/api/v1/notifications/post', form: {msg:msg, userID:userID}}, function(err, httpResponse, body){ if(err) return 0; els

Axios makes a request, sending parameters and data

Matthew Spahr I have a simple todo app and am using the edit tasks feature. After testing, my backend seems to be working fine. I am looking for req.body.description. I am editing tasks by ID. After saving the edits, nothing happens inside the database. My fun

PHP returns no data when sending ajax request

beans, lentils When I send an ajax post request to my getMessages.php file it returns nothing. I've tried manually setting the array values and printing them in the console and that seems to work. get message.php <?php require_once "mysqli.php"; $data = arra

XMLHTTP request not sending data to PHP file

Applef I'm using an xmlhttp request to send data to my php file and then using it to get the data from the database and then displaying that response on my original page. Here is the code: <script> function func2(str) { if (str == "") { document.getEleme

Objective C post request not sending data

ios development good day. I am trying to send simple post data to the server. This is my code. -(void)makeRequest:(NSString*)stringParameters{ NSError *error; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfigu

Error sending data using POST request in Android

Nikolai Stankovic I always get the same error when sending the username and password to the server. I need to send the data as content-type: form-data because the server doesn't respond to any other type. I tested in postman and it's ok, but when I try to send

No data response when sending ajax request to php

Markop I want to send a json data to my php but when i access it to my php there is no response. this is my ajax request var project = {project:"A"}; var dataPost = JSON.stringify(project); $.ajax({ url: 'fetchDate.php', data: {myData: da

Ajax request not sending data via POST

grumpy croton I have the following Javascript function http_post = function (url, data, success) { var json_data = JSON.stringify(data); return $.ajax({ type: "POST", url: url, data: json_data, dataType: "json",

Rectangular DELETE request, sending data in the body

Sergey Tyupaev I am using restangular to send DELETE request. I send some data in the request and add the data to the query string. But I want to use body instead of URI. I found this question on stackoverflow . This problem can be solved by using methods , Mg

Objective C post request not sending data

ios development good day. I am trying to send simple post data to the server. This is my code. -(void)makeRequest:(NSString*)stringParameters{ NSError *error; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfigu

Objective C post request not sending data

ios development good day. I am trying to send simple post data to the server. This is my code. -(void)makeRequest:(NSString*)stringParameters{ NSError *error; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfigu

Objective C post request not sending data

ios development good day. I am trying to send simple post data to the server. This is my code. -(void)makeRequest:(NSString*)stringParameters{ NSError *error; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfigu

$http.get not sending data in request body

winner While using angular v1.3.1, I'm having the following problem trying to implement a facade for making http requests to a REST+JSON interface in the backend of a web application. I get something like this in the code: findSomething(value: number): ng.IPro