cloud-functions-python | Get some python in google cloud functions
kandi X-RAY | cloud-functions-python Summary
kandi X-RAY | cloud-functions-python Summary
[NOTE]: This is a highly experimental (and proof of concept) library so do not expect all python packages to work flawlessly. Also, cloud functions are now (Summer 2018) rolling out native support for python3 in EAP so that also might be an option, check out the #functions channel on googlecloud-community.slack.com where the product managers hang around and open to help you out!.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Builds the function
- Wrapper for build
- Return the path to the hooks directory
- Build a pyinstaller
- Handle an HTTP event
- Create a WSGI environment
- Return a JSON representation of the response
- Handle a bucket event
cloud-functions-python Key Features
cloud-functions-python Examples and Code Snippets
Community Discussions
Trending Discussions on cloud-functions-python
QUESTION
I created an API endpoint using Google Cloud Functions and am trying to call it from a JS fetch function.
I am running into errors that I am pretty sure are related to either CORS or the output format, but I'm not really sure what is going on. A few other SO questions are similar, and helped me realize I needed to remove the mode: "no-cors"
. Most mention enabling CORS on the BE, so I added response.headers.set('Access-Control-Allow-Origin', '*')
- which I learned of in this article - to ensure CORS would be enabled... But I still get the "Failed to fetch" error.
The Full Errors (reproducible in the live demo linked below) are:
Uncaught Error: Cannot add node 1 because a node with that id is already in the Store. (This one is probably unrelated?)
Access to fetch at 'https://us-central1-stargazr-ncc-2893.cloudfunctions.net/nearest_csc?lat=37.75&lon=-122.5' from origin 'https://o2gxx.csb.app' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.
GET https://us-central1-stargazr-ncc-2893.cloudfunctions.net/nearest_csc?lat=37.75&lon=-122.5 net::ERR_FAILED
Uncaught (in promise) TypeError: Failed to fetch
See Code Snippets below, please note where I used <---- *** Message ***
to denote parts of the code that have recently changed, giving me one of those two errors.
Front End Code:
...ANSWER
Answered 2020-Jun-28 at 10:47Drop the part of your frontend code that adds a Access-Control-Allow-Origin
request header.
Never add Access-Control-Allow-Origin
as a request header in your frontend JavaScript code.
The only effect that’ll ever have is a negative one, in that it’ll cause browsers to do CORS preflight OPTIONS
requests even in cases when the actual (GET
, POST
, etc.) request from your frontend code would otherwise not trigger a preflight. And then the preflight will fail with this message:
Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response
…that is, it’ll fail with that unless the server the request is being made to has been configured to send an Access-Control-Allow-Headers: Access-Control-Allow-Origin
response header.
But you never want Access-Control-Allow-Origin
in the Access-Control-Allow-Headers
response-header value. If that ends up making things work, you’re actually just fixing the wrong problem. Because the real fix is: never set Access-Control-Allow-Origin
as a request header.
Intuitively, it may seem logical to maybe look at it as “I’ve set Access-Control-Allow-Origin
both in the request and in the response, so that should be better than just having it in the response” — but it’s actually worse than only setting it in the response (for the reasons described above).
So the bottom line: Access-Control-Allow-Origin
is solely a response header, not a request header. So you only ever want to set it in server-side response code, not frontend JavaScript code.
The code in the question was also trying to add an Origin
header. You also never want to try to set that header in your frontend JavaScript code.
Unlike the case with the Access-Control-Allow-Origin
header, Origin
is actually a request header — but it’s a special header that’s controlled completely by browsers, and browsers won’t ever allow your frontend JavaScript code to set it. So don’t ever try to.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cloud-functions-python
You can use cloud-functions-python like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page