I have built a Python Firebase Function that sends out an external API request using the ‘requests’ library. For example:
# Setup firebase tools
from firebase_functions import options, https_fn
from firebase_admin import initialize_app
import requests
initialize_app()
@https_fn.on_request(
cors=options.CorsOptions(
cors_origins="*",
cors_methods=["get", "post"]
)
)
def entity_requests(request: https_fn.Request) -> https_fn.Response:
"""This is a firebase function that calls out to an external API"""
# Example API request
response = requests.get('https://api.example.com/data')
status = response.status_code
data = response.json()
return https_fn.Response(data, status=status)
I can run the request on my local machine no problem, but when I try to run it in the firebase function, I get a response saying “The Url field is not a valid fully-qualified http, https, or ftp URL.” Any ideas why this is? Side note, I am paying for the blaze plan.
At this point I’m not exactly sure what to try. As I mentioned, I made sure my request code was good by testing it locally and had no issues. Now I am trying to figure out why it wont work when invoked inside the firebase function.
Preston Hollis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.