jaraco / wolframalpha

MIT License
148 stars 26 forks source link

Should not urlencode params #14

Closed riley-martine closed 6 years ago

riley-martine commented 6 years ago

I want to get the step-by-step solution for a problem. My real query that works via curl looks like this:

http://api.wolframalpha.com/v2/query?podstate=Solution__Step-by-step+solution&input=11x%2B18%3D172&appid=XXX

When I use the code

equation = "11x+18=172"
params = (
    ('podstate', 'Solution__Step-by-step+solution'),
)
res = client.query(f"{equation}", params=params)

I get the query

https://api.wolframalpha.com/v2/query?podstate=Solution__Step-by-step%2Bsolution&input=11x%2B18%3D172&appid=XXX

This urlencodes the '+' in Solution__Step-by-step+solution and the parameter fails to resolve.

You can test the difference with

APPID=YOUR_APP_ID
curl "https://api.wolframalpha.com/v2/query?podstate=Solution__Step-by-step+solution&input=11x%2B18%3D172&appid=$APPID" > manual
curl "https://api.wolframalpha.com/v2/query?podstate=Solution__Step-by-step%2Bsolution&input=11x%2B18%3D172&appid=$APPID" > auto
diff manual auto
jaraco commented 6 years ago

Im pretty sure the issue you have here is the plus is already encoded so is getting double encoded. I suspect all you need to do is put a space where that plus is and let the encoding happen by the library as it should. See this question for more info.