[python3]remove whitespaces from json requests post body?

Nighcore2

Registered Member
Joined
Apr 30, 2019
Messages
69
Reaction score
4
Im trying to imitate http request i sniffed both requests with charlesproxy and they are indentical unless the Content-Length header + body whitespaces
Code:
data=["Machine gun Kelly23","123456789","2.29.0"]

after thath
Code:
response = session.post('https://www.guerrastribales.es/m/m/login', json=data)

original response body
Code:
["Machine gun Kelly23","123456789","2.29.0"]
my python body
Code:
["Machine gun Kelly23", "123456789", "2.29.0"]

Need to remove those 2 whitespaces after the "," someone knows how to do it?

btw the rest is the same check headers here
my python script headers
Code:
Accept-Encoding: identity
Host: www.guerrastribales.es
Acecept-Encoding: deflate, gzip
Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, */*;q=0.5
User-Agent: Mozilla/5.0 (Android; U; es-ES) AppleWebKit/533.19.4 (KHTML, like Gecko) AdobeAIR/31.0
x-flash-version: 31,0,0,101
Connection: Keep-Alive
Cache-Control: no-cache
Referer: app:/staemme.swf
Content-Type: flv-application/octet-stream; charset=UTF-8
IGMobileDevice: Android
Content-Length: 46
original http headers
Code:
POST /m/m/login?hash=851f8c19a97e88fe4c553842c28d16ec37ee3f18 HTTP/1.1
Host: www.guerrastribales.es
Accept-Encoding: deflate, gzip
Accept: text/xml, application/xml, application/xhtml+xml, text/html;q=0.9, text/plain;q=0.8, text/css, image/png, image/jpeg, image/gif;q=0.8, application/x-shockwave-flash, video/mp4;q=0.9, flv-application/octet-stream;q=0.8, video/x-flv;q=0.7, audio/mp4, application/futuresplash, */*;q=0.5
User-Agent: Mozilla/5.0 (Android; U; es-ES) AppleWebKit/533.19.4 (KHTML, like Gecko) AdobeAIR/31.0
x-flash-version: 31,0,0,101
Connection: Keep-Alive
Cache-Control: no-cache
Referer: app:/staemme.swf
Content-Type: flv-application/octet-stream; charset=UTF-8
IGMobileDevice: Android
Content-Length: 44

Just content-length changes due to body 2 extra whitespace characters
 
You’re comparing the length of a string to the output of a list, so you need to convert your list to a string.
 
its the standart python whitespaces. This is what the list looks like in python. You can check it easily. Create a list , example list = [1,2,3,4] print(list) , and you will see the same whitespaces between the elements as your situation. If you want to delete whitespaces from that string use replace function. Example:

strk = "['Machine gun Kelly23', '123456789', '2.29.0']".replace(" ","")
print(strk)

sorry for my English, I hope I understand you correctly.
 
its the standart python whitespaces. This is what the list looks like in python. You can check it easily. Create a list , example list = [1,2,3,4] print(list) , and you will see the same whitespaces between the elements as your situation. If you want to delete whitespaces from that string use replace function. Example:

strk = "['Machine gun Kelly23', '123456789', '2.29.0']".replace(" ","")
print(strk)

sorry for my English, I hope I understand you correctly.
Wrong bro, your solution is going to replace ALL spaces in string, OP dont want that.

@Nighcore2
Code:
x = '["Machine gun Kelly23", "123456789", "2.29.0"]'
y = x.replace('", "', '","')
y
'["Machine gun Kelly23","123456789","2.29.0"]'
 
Back
Top