2

The URL that I need to GET from looks something like this:

https://example.com//report.php?file=MyFile&params=query=QueryMyFile^SomeParam=x^SomeOtherParam=y^AnotherOne=z

I want to use requests to pass the params; something along the lines of:

base_url = 'https://example.com//report.php'
params = 
{ 'SomeParam': x,
  'SomeOtherParam': y,
  'AnotherOne': z
}

my_file = requests.get(base_url, params=params)

How can I achieve this?

3 Answers 3

2

They're accepting them all in one query called "params".

That's a non-standard way to send params, so, there's no built-in way to do that with requests. You'll have to join the keys and values with '^' character manually.

Sign up to request clarification or add additional context in comments.

5 Comments

Hmm, that sucks. What about using urllib?
Not even urllib.parse.urlencode() will help here, since you can't specify a different separator.
Nope. Blame whoever designed the report.php.
You should be able to mash the parameters together in the url in the format you need, and then just use requests to 'get' that url.
@SuperStew that is already what I am doing; I was looking for a more formal/standard way of doing it.
0

From the requests docs..

payload = {'key1': 'value1', 'key2': 'value2'}
r = requests.get('http://httpbin.org/get', params=payload)

Comments

0

The structure of your params data is in json style, i would also try to do it this way instead:

    import json
    import requests

    params = { 'SomeParam': x,
    'SomeOtherParam': y,
    'AnotherOne': z }

    params = json.dumps(params, separators=('^', '='))
    params = params[1:-1] #remove first and last curly brackets
    my_file = requests.get(base_url+params)

Something like that would do.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.