SSL Error: Bad handshake (Python requests) - python

I know similar questions have been asked before but I have read all of them and I still cannot figure out a solution for my problem.
I am basically working behind a corporate proxy, so when I do for a example a get request to Google with something like this:
import requests
requests.get('https://www.google.es')
I immediately get an error which points towards a fail in certificate verification. After much reading I have found this post where you can get a sweet explanation of what is going on.
Some solutions I have tried are:
1.https://stackoverflow.com/a/42540637/8380638
2.https://stackoverflow.com/a/48636689/8380638
But still I could not make this work.
My main goal is using Google Translate API from google.cloud python module which uses requests on it. So it would be good to find some fix that goes further from adding a parameter into request.get() function.

You can get the Google Translate API without using the requests library. Simply install the google-cloud-translate library and setup the required authentication on your Google Cloud Platform account as described in the documentation. Once completed, you can directly import the Translate API using the following line:
from google.cloud import translate

I finally found the solution for this, but I forgot to post it.
You can use this to find the path where request library CAs are stored and add your own one at the end of the file.
import requests as r
print(r.certs.where())

Related

How to receive URL File as parameter and save it to disk using FastAPI?

I would like to know if there is a way for FastAPI to receive a URL of a file as a parameter and save this file to disk? I know it is possible with the requests library using requests.get() method, but is it possible with FastAPI to receive the URL and save it directly?
I tried using file: UploadFile = File(...), but then it doesn't download the file when the URL is sent.
I don't believe so. I've come across this before and was unable to find a solution (and ended up using requests like you mentioned), but seeing this I wanted to check again more thoroughly.
Reviewing the uvicorn and fastapi repositories by searching the code itself, I see no functions/code that reference requests or urllib (they do use urllib.parse/quote, etc though) that would be 2 likely suspects to build requests. They do use httpx.AsyncClient, but only in tests. I would expect to see some use of these libraries in the main uvicorn/fastapi libraries if they had code to make external requests.
Seeing the above, I actually think I will change my code to use httpx.AsyncClient anyways since it is already a dependency.

How do I format get requests to Blogger API in Python?

I'm new to Python and API's. I'm trying to work on a project and need some help.
I just want to request some information from Blogger to get back blog post details (title, body, etc) and return it.
I'm wanting to use these: https://developers.google.com/resources/api-libraries/documentation/blogger/v3/python/latest/blogger_v3.blogs.html
I can use requests.get(url/key) and I get a server status[200], but everytime I try to find a way to use one of the requests from the link I get keyword errors.
For example: "TypeError: request() got an unexpected keyword argument 'blogId'"
My code is requests.get('url/key' blogId='BLOG ID HERE', x__xgafv=None, maxPosts=None, view=None)
I don't feel comfortable posting my exact code, since it has my API in it.
What am I doing wrong?
request.get() method doesn't have blogID parameter. For more info use this link
I am not sure, but oyu can use params like that:
page = get('https://google.com', params={'blogId': '12345'})
It's better to look up information in the docs: https://requests.readthedocs.io/en/master/
I found my solution after digging a bit.
I was using get requests on the API to get a response, which is how it should be used.
Yet, I was also trying to use a method of returning data that also used the get keyword, but was meant for use with the Google API Library.
I had to install the Google API Client library and import build, and requests so that I could use the API methods instead. This allows me to return results that are far more specific (hence the keyword arguments), and can be programmed to do a number of things.
Thanks everyone!

how to implement the aws glacier example request in Python?

I am trying to figure out how to do multipart-uploads to AWS Glacier and found some Example Request on this documentation page. How do I implement this example in Python? I think I should use the 'requests' module but don't know exactly how to make it work.
Here is what I have done:
import requests
r = requests.post('/042415267352/vaults/history/multipart-uploads')
And this is the error I have:
MissingSchema: Invalid URL '/042415267352/vaults/history/multipart-uploads': No schema supplied.
Perhaps you meant http:///042415267352/vaults/history/multipart-uploads?
I am having this trouble because I don't really understand these stuff, HTTP request, RESTFul API etc.If someone can suggest some resources for me to learn these, in addition to helping out with this specific question, that will be great! Because I don't want to come here ask question again if I come across similar situation in the future. But for now, I even don't know where to start the learning process.
Your help are highly appreciated!
You do not need to implement low level HTTP requests yourself, this is what boto module is for in Python. You can do all this via module which abstracts all low level requests for you.
For documentation and examples, see Boto3 Glacier docs which contains lots of examples.
requests.post expects an absolute path. Prepend the scheme (http or https, or whichever else) to the relative URL.

How to structure get 'review link' request from Vimeo API?

How to structure GET 'review link' request from Vimeo API?
New to python and assume others might benefit from my ignorance.
I'm simply trying to upload via the new vimeo api and return a 'review link'.
Are there current examples of the vimeo-api in python? I've read the documentation and can upload perfectly fine. However, when it comes to the http GET I can't seem to figure it out. Im using python2.7.5 and have tried requests library. Im ready to give up and just go back to PHP because its documented so much better.
Any python programmers out there familiar?
EDIT: Since this was written the vimeo.py library was rebuilt. This is now as simple as taking the API URI and requesting vc.get('/videos/105113459') and looking for the review link in the response.
The original:
If you know the API URL you want to retrieve this for, you can convert it into a vimeo.py call by replacing the slashes with dots. The issue with this is that in Python attributes (things separated by the dots), are syntax errors.
With our original rule, if you wanted to see /videos/105113459 in the python library you would do vc.videos.105113459() (if you had vc = vimeo.VimeoClient(<your token and app data>)).
To resolve this you can instead use python's getattr() built-in function to retrieve this. In the end you use getattr(vc.videos, '105113459')() and it will return the result of GET /videos/105113459.
I know it's a bit complicated, but rest assured there are improvements that we're working on to eliminate this common workaround.

Python JIRA SOAPpy annoying redirect on findIssue

I am trying to do WSDL SOAP connection to our JIRA server using SOAPpy (Python SOAP Library).
All seems to be fine except when I try finding specific issues. Through the web browser looking up the bug ID actually redirects to a bug (with a different ID), however it is the bug in question just moved to a different project.
Attempts to getIssue via the SOAPpy API results in an exception that the issue does not exist.
Any way around this?
Thanks
Yes, there's an existing bug on this I've seen. Use the JIRA issue id instead of the key to locate it, as a workaround.

Categories