Reputation: 168
I have billing enabled for my project, however, I keep on getting an error returned:
Error: could not handle the request
And the traceback:
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/opt/python3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/opt/python3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/python3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Here is my code:
import json
from google.cloud import storage
import requests
def call(request):
url = "https://jsonplaceholder.typicode.com/todos/"
response = requests.get(url)
json_data = response.json()
pretty_json = json.dumps(json_data)
print(pretty_json)
With requirements being:
requests
google.cloud.storage
Upvotes: 0
Views: 84
Reputation: 40061
The following should work for you:
python3 -m venv venv
source venv/bin/activate
python3 -m pip install requests
import json
import requests
url = "https://jsonplaceholder.typicode.com/todos/"
response = requests.get(url)
print(response.status_code)
print(response.text)
python3 main.py
200
[
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},
...
]
Upvotes: 1