socket.gaierror: [Errno -2] Name or service not known | Firebase x Raspberry Pi


I am using a Python program to click a picture on my Raspberry Pi 3B+ when motion is detected and send this image to firebase storage.

import RPi.GPIO as GPIO
import gpiozero
import datetime
import picamera
import time
import os
import pyrebase

firebase_config = {
  "apiKey": "...",
  "authDomain": "",
  "databaseURL": "",
  "projectId": "...",
  "storageBucket": "",
  "messagingSenderId": "...",
  "appId": "..."
firebase = pyrebase.initialize_app(firebase_config)
storage =

# Camera config
camera = picamera.PiCamera()

# Motion sensor
pir = gpiozero.MotionSensor(4)

print("Waiting for motion")
print(f"Motion detected")

filename ="%d%m%y%H%M%S")+".jpg"
print(f"{filename} saved")

print("Image sent to firebase")


The picture gets clicked and saved on Pi but does not get sent to Firebase storage due to the following error:

Waiting for motion
Motion detected
080524135451.jpg saved
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/requests/packages/urllib3/", line 141, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.9/dist-packages/requests/packages/urllib3/util/", line 75, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.9/", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/raspi/Desktop/", line 42, in <module>
  File "/usr/local/lib/python3.9/dist-packages/pyrebase/", line 405, in put
    request_object =, data=file_object)
  File "/usr/local/lib/python3.9/dist-packages/requests/", line 522, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/requests/", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/dist-packages/requests/", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/requests/", line 487, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='', port=443): Max retries exceeded with url: /v0/b/ (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x72df5268>: Failed to establish a new connection: [Errno -2] Name or service not known'))

I tried the same task on my local computer using an existing photo and it worked => the account settings are fine.

Asked By: peacer



Since you have been able to successfully transfer data using your local computer, this is purely a Pi and/or network issue. The error "socket. gaierror: [Errno -2] Name or service not known" typically points to a DNS resolution issue. This error indicates that the hostname used in your application cannot be resolved to an IP address.

With that said:

  1. Recheck your internet connection.
  2. Ensure that if you’re on restricted network (like office/school wifi), your Raspberry Pi is registered to it.

Hope this helps!

Answered By: Himanshu saraswat
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.