0

I try to using request.get with '@' in params, but in output I have '%40' How I can decode this dict?

Using Python3

import requests payload = {'OPERATION-NAME': 'findItemsByProduct','productId.@type':'ReferenceID'} req = requests.post(url, params=payload) print(req.url) 

The output is - 'url?productId.%40type=ReferenceID'

7
  • Maybe this is what you're looking for? Commented Dec 5, 2017 at 19:46
  • I checked this too, does not work Commented Dec 5, 2017 at 19:54
  • Using urllib.parse.unquote: unquote("url?productId.%40type=ReferenceID") returns 'url?productId.@type=ReferenceID'. What's wrong about that? Commented Dec 5, 2017 at 19:57
  • AttributeError: 'dict' object has no attribute 'split' Commented Dec 5, 2017 at 20:08
  • 1
    Heya, the comment section isn't for discussing new problems that arise. If you've solved it partially and are getting new exceptions, it's time to open a new question (after doing proper research!) :) Commented Dec 5, 2017 at 20:09

1 Answer 1

1

Use "data" argument instead of params. You should also specify the header, in this case json and then convert the payload dict to json using json.dumps().

import requests import json payload = {'productId.@type':'ReferenceID'} req = requests.post(url, headers={'Content-Type': 'application/JSON'}, data=json.dumps(payload)) print(req.url) 
Sign up to request clarification or add additional context in comments.

7 Comments

I see you answered OP, but didn't provide an explanation. Please include some context in your answer.
I forgot to include the header, try again and let me know. Make sure you have a valid url. BTW what you get is not the request (req) it's the response so you should rename req by resp.
TypeError: request() got an unexpected keyword argument 'header'
What python are you using? Pyhton2 / Python3, What requests version??
My bad it's 'headers' plural. I didn't test the code just writing from my head. It should work.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.