Postman request with % not working while generated cURL snippet works - postman

I'm trying to access an API. The auth endpoint expects a username and password query parameter.
The password (not set by me) contains two special characters, # and %. The # gets URL encoded correctly, but the % doesn't (as per Postman documentation). Thus, I updated the password variable and replaced the % with %25.
So, if the password is p#ssw%rd Postman turns that into p%23ssw%rd. I updated the variable to p#ssw%25rd, encoding the % only. So the final URL encoded string should be p%23ssw%25rd, which is what the cURL snippet shows!
However, the API still returns invalid credentials. If I copy-paste the generated URL from the cURL snipped and post that URL in my browser I am able to login.
I'm curious if there's a solution for this out there?

Related

Postman: Is it possible to update url of postman request in the pre-requisite script

Is it possible to update url of postman request in the pre-requisite script.
I want to edit the url based on dynamic environment input.
For example:
if (environment.someValue) {
request.url = request.url + "\" + environment.someValue
if (environment.anotherValue) {
request.url = request.url + "\" + environment.anotherValue
}
}
console.log(request.url);
The above code gives me prefect console log:
e.g. if url is https://someServer/someRequest, environment.someVar is x and environment.anotherVar is y the console.log(request.url) above prints:
https://someServer/someRequest/x/y
But the problem is (say if i am requesting a Get), even after logging the overridden request url, it only calls https://someServer/someRequest and does not override to https://someServer/someRequest/x/y.
Any ideas how to modify the url as asked above.
if your url in your request is set as a global, it should work.
ie. I have a get request :
GET http://{{myurl}}/etc. with myurl set as a global variable
In my prerequest script I do pm.globals.set("myurl", <new url>);
when I launch my request, it tries to do the GET request on my new url.
So it is possible to do it but you have to use global or environment variables to dynamically update your request:
set your 'someRequest' as a global that you can update in your prescript (instead of request.url), then it will be interpreted when you launch your request
https://someServer/{{someRequest}}
pm.request.url= "dynamic value"
you and update url using the above single line in postman prerequisite step
pm.request.url returns a object with fields host,path and params . But you can replace it with string.
Thanks for the tips: I used these lines of code to manipulate two values that appear in a RESTful API route:
// Ensure Payroll ID and Employee ID in request URL are correctly padded with zeros
pm.request.url.path[pm.request.url.path.indexOf("{{PayrollID}}")] = data.PayrollID.toString().padStart(6, '0');
pm.request.url.path[pm.request.url.path.indexOf("{{EmployeeID}}")] = data.EmployeeID.toString().padStart(7, '0');

How to avoid user having to re-authorize Evernote every time?

I'm building a Python web app with the Evernote API. When users log in they're redirected to a page on the Evernote site to authorize the application. When they come back everything works fine (can see and edit notes etc.)
The challenge now is to avoid having to redirect the user to the Evernote site every time they log on.
I read on the Evernote forums that I need to save the access token and the notestore url to achieve this. I now save these to the users accounts after the first successful authorization.
But how do I use the access token and notestore url to authorize?
I found this sample code on the Evernote website that's supposed to achieve this, but it's in Java and I can't seem to make it work in Python.
// Retrieved during authentication:
String authToken = ...
String noteStoreUrl = ...
String userAgent = myCompanyName + " " + myAppName + "/" + myAppVersion;
THttpClient noteStoreTrans = new THttpClient(noteStoreUrl);
userStoreTrans.setCustomHeader("User-Agent", userAgent);
TBinaryProtocol noteStoreProt = new TBinaryProtocol(noteStoreTrans);
NoteStore.Client noteStore = new NoteStore.Client(noteStoreProt, noteStoreProt);
Basically, if you got the notestore url and access token from a previous authorization, how do you use them to re-authorize?
If you have the access token, you will use that as a constructor argument for the EvernoteClient class.
For example:
client = EvernoteClient(token=your_access_token)
note_store = client.get_note_store()
notebooks = note_store.listNotebooks();
for n in notebooks:
print n.name
For more examples, check out the Python Quick-start Guide.

How can I send a request to a view from an admin command without hard coding the url

I am trying to create an admin command that will simulate some api calls associated with a view but I don't want to hard code the url, for example like that url='http://127.0.0.1:8000/api/viewname', in order to send the request.
If I use the reverse option I can obtain half the url /api/viewname.
If I try to post the request that way
url = reverse('name-of-view')
requests.post(url, data=some_data)
I get
requests.exceptions.MissingSchema: Invalid URL '/api/viewname/': No schema supplied. Perhaps you meant http:///api/viewname/?
Do I have to look whether the server is running on the localhost or is there a more generic way?
requests module needs the absolute url to post to. you need
url = 'http://%s%s' % (request.META['HTTP_HOST'], reverse('name-of-view'))
requests.post(url, data=some_data)

In python-oauth2 how do you retain oauth_token_secret parameter?

I'm trying to follow this Oauth2 guide for Sign in With Twitter https://github.com/simplegeo/python-oauth2 - Everything is going great until between steps 2 and 3. I handle the the callback fine, but how do I pass along the oauth_token_secret? My confusion is that it seems like it's lost after the redirect back to my handler.
From what I can tell the parameters I get back are oauth_token and oauth_verifier, and yet I need the oauth_token_secret to receive the access token in these steps.
token = oauth.Token(request_token['oauth_token'],
request_token['oauth_token_secret'])
token.set_verifier(oauth_verifier)
client = oauth.Client(consumer, token)
resp, content = client.request(access_token_url, "POST")
access_token = dict(urlparse.parse_qsl(content))
Am I supposed to store it in a cookie to retrieve later?
I was able to do this by storing the oauth_token and oauth_token_secret in a session during step one. These values are stored from the created request token request_token['oauth_token']

Django-social-auth google oauth token usage

I'm using Django-socila-auth plugin. It uses google API for Oauth 1.0 Authentication. Question is have anybody used it with google python API (gdata). I mean how to apply auth session_token, stored in django-social-auth model to my api call.
Can you help me with code to get this token from model and apply to gdata.PhotoService() instance. For now it is like this:
#getting model instance from django-social-auth model
association = Association.objects.get(user=request.user)
google_session_token=association.handle
google_secret=association.secret
#token string from django-social-auth
#model Association field "handle" looks like:
#google_session_token = '.......XG84PjwytqJkvr8WQhDxm1w-JplWK5zPndSHB13f.........'
gd_client = gdata.photos.service.PhotosService()
gd_client.debug = 'true'
gd_client.auth_token = google_session_token
#image.image is a file field, but problem not in this.
#it tries to send file in debug text.
#It just recieves 403 unauthorised callback.
photo = gd_client.InsertPhotoSimple(
'/data/feed/api/user/default/albumid/default', 'New Photo',
'Uploaded using the API', image.image, content_type='image/jpeg')
I'm recieving error
403 Invalid token string.
I understand that it needs secret too but how to apply it to API for auth?(To receive authorization to post photos.). BTW I added Picassa feed URL, as an option string for social-auth to ask permissions, so token I have asks for Picassa feed permissions when authorizing with google.
BTW. Google tutorial I've used is: here
I understand it's Oauth 1.0 rather than AusSub, but question is:
how to authenticate with token and secret I have and post a photo with this permission?
Just to answer my own problem. I used wrong way to do it, because problem in 'gd_client' and AuthSub.
It must check token on server. And it can not do it on localhost. You need to look ahead to Oauth/Oauth2 for better debugging and so on... No matter that it is much complex than AuthSub