oauth - OAuth1Session Encoding of URL Django -
alright, need assistance think easy question, after digging quite while i'll leave brilliant people show me why i'm not!
i'm attempting access provider api, url i'm attempting access being: .../proposals/anothertestproposal/city_furniture/items?filter=description$cont"ag"
:: way want passed, , should return items who's descriptions contain string "ag". know have 2 of currently.
i'm using django 1.9.4, , requests_oauthlib create oauth1session, i'm doing also, because can access resources without url params. trouble can't "?filter=description..."
part encode , it's giving me 401.
when render .contents html get:
{"status": 404, "message": "", "data": [], "arguments": {"id": "items?filter=description$cont\"ag\"", "collection": "city_furniture"}}
which telling telling me "ag" part being escaped, don't want. in: don't want \"ag\", want "ag".
so, question: how can pass url, params, not containing slashes these causing url invalid , therefore keeping me accessing data correctly?
other, possibly irrelevant info:
the params part of url string i'm passing oauth1session object is:
'/city_furniture/items%3ffilter%3ddescription%24cont%22ag%22'
an example of filtering api's website:
proposals/master/roads/items?filter=description$cont"highway"
i tried passing 'encoding' arg .get (in order change encoding used to_native_string) requests rejected saying invalid arg
per comments, additional code. using function name get_protected_code()
oauth info passed correctly, in views.py
:
api_filter_url = settings.iw_api_model_collection + '/' + model_id + '/' + settings.iw_api_proposal_collection + '/' + proposal_name + '/city_furniture/items%3ffilter%3ddescription%24cont%22ag%22' json_model_info_pull = get_protected_data(api_filter_url) find_vendor = json_model_info_pull.content def get_protected_data(url_str): ## ...stuffs create oauth1session... adsk_pull = oauth1session(key, client_secret=secret, resource_owner_key=oauth_token_use, resource_owner_secret=oauth_token_secret_use, ) headers = {'accept': 'application/vnd.autodesk.infraworks-v1+json'} api_url = settings.adsk_iw_info_base_url + url_str json_model_info_pull = adsk_pull.get(api_url, headers=headers) return json_model_info_pull
looks you're passing parameters incorrectly appending them end of url in url-encoding, requests
respecting intentional, , api endpoint translating in unintended manner.
from the documentation requests
, should provide params
keyword argument requests.get
: dict
containing key-value pairs should encoded , sent query string request. example, run query against the github api, can pass api token query parameter:
requests.get('http://api.github.com/user', params={ 'access_token' : my_oauth_token })
the resultant request contain query string access_token
parameter set value stored in my_oauth_token
, escaped properly, needed. (such tokens typically contain =
characters, example, invalid inside query string values.)
Comments
Post a Comment