Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP request not working as expected, SSL error #607

Open
varogonz95 opened this issue Aug 13, 2023 · 0 comments
Open

HTTP request not working as expected, SSL error #607

varogonz95 opened this issue Aug 13, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@varogonz95
Copy link

varogonz95 commented Aug 13, 2023

Tip: From Visual Studio Code, you can use the command DeviceScript: Report Issue... to prefill the issue template.

Describe the bug
From a ESP32 device, I want to post some data to a Cloud Firestore, thus I'm using fetch(...) function to achieve that.
The store is currently unprotected for the moment, so any data can be posted without much overhead.
Thing is, I get a socket tls://firestore.googleapis.com:443 error tls://firestore.googleapis.com:443: self-signed certificate.
This is my code:

const url = `https://firestore.googleapis.com/v1/projects/{PROJECT_ID}/databases/(default)/documents/{COLLECTION_ID}`
const options = {
    method: "POST",
    body: JSON.stringify(...),
    headers: { "Content-Type": "application/json", key: API_KEY }
}
const response = await fetch(url, options)
//...

NOTE: I tried exactly the same with MicroPython, and works like a charm.
Here is my python code:

import urequests
#...
response = urequests.post(
    f'https://firestore.googleapis.com/v1/projects/{PROJECT_ID}/databases/(default)/documents/{COLLECTION_ID}',
    json=data,
    headers={
        'Content-Type': 'application/json',
        'key': C.FIRESTORE_API_KEY
    },
)

So, how's this different from what I'm doing with MicroPython?

To Reproduce
Steps to reproduce the behavior:

  1. Connect device to WIFI access
  2. Make a fetch(...) request to Cloud Firestore
  3. Get SSL Self Signed Cert error
  4. Cry

Expected behavior
Be able to successfully make a request to Cloud Firestore.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Console Output:

VM> connecting to tls://firestore.googleapis.com:443
VM> socket tls://firestore.googleapis.com:443 open undefined
VM> req: POST /v1/projects/[PROJECT_ID]/databases/(default)/documents/sensors HTTP/1.1
VM> content-type: application/json
VM> key: [API_KEY]
VM> user-agent: DeviceScript fetch()
VM> accept: */*
VM> host: firestore.googleapis.com
VM> connection: close
VM> content-length: 2
VM>
VM> socket tls://firestore.googleapis.com:443 error tls://firestore.googleapis.com:443: self-signed certificate
@varogonz95 varogonz95 added the bug Something isn't working label Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant