Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display_filter is urlencoded by the Requests library #1

Open
jroakes opened this issue Feb 28, 2018 · 0 comments
Open

display_filter is urlencoded by the Requests library #1

jroakes opened this issue Feb 28, 2018 · 0 comments

Comments

@jroakes
Copy link

jroakes commented Feb 28, 2018

This repo, uses the requests library to hit the api URL and manage parameters. One issue with this is that when using display_filter, the api expects:

+|Ur|Co|electrical-supplies
(include|URL|Containing|electrical-supplies)

to be:

%2B|Ur|Co|electrical-supplies

if you pass this string to the client.domain_organic method, it will be converted to:

%252B%7CUr%7CCo%7Celectrical-supplies

when Requests builds the URL request.

a workaround is to do the following:

url = "electrical-supplies"
display_filter = quote("+|Ur|Co|" + url, safe='|/', encoding=None, errors=None)    
client.api_url = 'http://api.semrush.com/?display_filter='+display_filter
data = client.domain_organic(domain="domain.com", database='us',display_limit=5,export_columns='Ur,Po,Ph,Nq')

The solution would be to simply have the retrieve method of the SemrushClient class handle a kwargs key of 'display_filter' directly on the api URL and let requests handle the remaining params.

There may be some other way to hook into urlencode, or the Requests library to skip encoding '|' characters, but I am not aware of any.

I realize this is a couple-year-old repo, so understood if not wanting to look at. I wanted to leave this here in case someone ran into the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant