How to perform a signed PUT request with OAuth in Python - python

How is this meant to work? Where are all the oauth_* values meant to go if not in an encoded body like a POST request? In what form do you sign it?
All the Python OAuth libraries I can find only support GET and POST. Does anyone know any that support all methods?

python-oauth2 supports all HTTP verbs -- as the comment I've linked to says, and I quote,
We use PUT extensively at SimpleGeo
(our python-simplegeo package uses
python-oauth2 and PUT requests).
The python-oauth2 package's client
(oauth2.Client) simply wraps httplib2,
which supports all of the verbs AFAIK.
So were did you get the weird notion that python-oauth2 doesn't support PUT?

Related

Validate Request against OpenAPI YAML in Python

I have written API documentation using Open API 3 standards (using stoplight.io). Now I'm implementing the API in Python 3.7, and I don't want to rewrite all of the schemas, not to mention I'd like my API to be coupled with my documentation to prevent discrepancies.
I've found tools like pydantic and openapi-schema-validator that seem relevant, but don't fit my use case. For example, pydantic wants me to create the pythonic objects first and then export to json_schema and openapi-schema-validator wants just the json schema while I have an Open API yaml.
This seems like a standard question, but I haven't found a good answer. Thanks!
You could use openapi-core or connexion which both support request and response validation..

Tyk Plugin Python

I would like to use my own Auth service on every request. I found that by creating plugin is the best way to do it. I am just curious, How can I return an error directly after pre function ?
For example:
User access api
Plugin check the token that sent along with the api request
if it is false, then return error directly to user as Error HTTP 401 without
processing into the proxy url.
UPDATE
I got this error when using custom auth plugin:
{ "error": "Session state is missing or unset! Please make sure that auth headers are properly applied."}
And this is how I got there:
https://community.tyk.io/t/create-python-plugin/1369/6
Thanks
Information on how to write custom middleware in order to achieve this goal can be found in the official documentation. Tyk v2.3 currently supports plugins written in Python 3 as well as LuaJIT, ES5 and gRPC-compatible languages (e.g., Ruby, Java, .NET, &c.).
Further details regarding error templates can be found here, if needed.
The Session object does not exist in all the possible hooks, like the Pre Hook.

how to do http get with django

This should be one of the simplest things, but I can't find how to do it in the documentation. I have found how to do it python lib2, but I would like to do it with django to get back a status code, content, etc.
Something like:
response = httpget('http://my-ulr.com')
print response.status_code
This functionality is not part of Django (since the framework is designed mainly to serve request and not to make them), but Django is just Python - you can use Python's built-in urlib2 library, but I would strongly suggest using the excellent Requests library.
Requests is really fun to work with, and you can't say that about urlib2. You can even say Requests is quite djangish in its simple beauty, and it's creator Kenneth Reitz is an active member of the Django community. But anyways - djangish or not, it works great and you can use it in any Python code.
With Requests your example code would look like this:
import requests
response = requests.get('http://my-ulr.com')
print(response.status_code)

mod python, get POST parameters from request object

Is there any basic example that shows how to get POST parameters from the request in mod python custom handler. I have no trouble in GET requests, where I get my arguments from request.args, BUT if method is POST, request.args is None.
Thanks.
request.args stores query string parameters, as mentioned in the documentation.
If you want to get POST variables, you can always read the body of the request (request.read()) and parse it (urldecode in your case).
But keep in mind that, as mentioned on the official mod_python homepage:
Current State of Mod_Python
Currently mod_python is not under active development. This does not mean that it is "dead" as some people have claimed. It smiply means that the code and the project are mature enough when very little is required to maintain it.
Which means you may be better off using something more modern, like mod_wsgi.

Distinguishing between GET and POST data in CherryPy?

I've been deciding between Python web frameworks for a project of mine and I've really liked how lightweight, flexible, and concise CherryPy is compared to others. The only problem I'm having is I can't find any documentation on how to distinguish between data sent via GET and via POST.
For example, I don't want users to be able to provide their login credentials through a GET request (http://example.com/login?username=user&password=pass) but, according to CherryPy's tutorial, all data is sent as method parameters, no matter what HTTP method they're sent as. Is there some way to say I only want the POST data or do I have to use MethodDispatcher?
Thanks!
See the docs.
A string containing the HTTP method, such as "GET" or "POST". Set
in the "run" phase.
looks like checking cherrypy.request.method is what you want to do.

Categories