Closed csbrown closed 5 years ago
urllib.parse.quote
will encode the &
s as %26
s, so you could use something like:
urllib.parse.quote("q=twitter&result_type=recent&since=2014-07-19&count=100", safe='&=/%')
However, if you have a & in the query string (like, "twi&tter" (not sure why you'd want to but it's possible)), then that would get passed unquoted and mess up the search.
I think the best option would be to construct a dictionary like this:
raw_query_params = {
'q': 'El Niño',
'result_type': 'recent',
'since': '2019-03-07',
'count': 100
}
results = api.GetSearch(raw_query=urllib.parse.urlencode(raw_query_params))
# constructs the following string:
# 'q=El+Ni%C3%B1o&result_type=recent&since=2019-03-07&count=100'
Per the docs, we can use this to perform a raw query search:
However, sometimes it is necessary to url encode the various weird symbols that go into a query. Python provides a handy function for this,
urllib.parse.quote
. However, it does not play well withapi.GetSearch
:gives
How do I get the api to play well with url encoded parameters?