I'm trying to post a request to the target website using multi part form data
m = MultipartEncoder(
fields={"auth":{"id":str(random.randint(0, 999991)),"sign":randoms(32)},
"data":{"action":"login","login":"embrella","password":"steffano321","stayLogged":"False"}
})
s = requests.Session()
s.post('targetwebsite', data=m, headers=headers['Content-Type': m.content_type], timeout=5)
But I always end up with
line 25, in <module>
"data":{"action":"login","login":"embrella","password":"steffano321","stayLogged":"False"}
AttributeError: 'dict' object has no attribute 'encode'
I don't know what's causing this, I've even tried converting to JSON first then posting
uuhh = {'auth':{"id":str(random.randint(0, 999991)),"sign":randoms(32)},
"data":{"action":"login","login":"embrella","password":"steffano321","stayLogged":"False"}}
fields = json.dumps(uuhh)
m = MultipartEncoder(fields=fields)
But it says ValueError: not enough values to unpack (expected 2, got 1) so I guess that is very wrong.
It seems that you are passing auth and data as a dictionaries but instead they should be strings. Change
m = MultipartEncoder(
fields={"auth":{"id":str(random.randint(0, 999991)),"sign":randoms(32)},
"data":{"action":"login","login":"embrella","password":"steffano321","stayLogged":"False"}
})
to
m = MultipartEncoder(
fields={"auth":'{{"id":{},"sign":{}}}'.format(random.randint(0, 999991), randoms(32)),
"data":'{{"action":"login","login":"embrella","password":"steffano321","stayLogged":"False"}}'
})
to fix your issue.
MultipartEncoder tries to run .encode(...) method on the values of fields.
Since you're passing a dict, it fails to encode and the error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With