Pyrebase icon indicating copy to clipboard operation
Pyrebase copied to clipboard

Getting TypeError: request() got an unexpected keyword argument 'build_headers'

Open abvijaykumar opened this issue 6 years ago • 14 comments

Hi - I am trying to use the SSE client streams with pyre base here is the code (took it from example as it is)

def command_handler(message): print('event: ' + str(message["event"])) # put print('path: ' + str(message["path"])) # /-K7yGTTEp7O549EzTYtI print('data: ' + str(message["data"])) # {'title': 'Pyrebase', "body": "etc..."}

my_stream = db.child("child1").child("child2").stream(command_handler)

this is working fine on my mac, but when I try it on my raspberry pi, I get the following stack trace.

pi@raspberrypi:~/abDev/ArioHome $ python3 arioHomeServer.py connected Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/usr/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.5/dist-packages/pyrebase/pyrebase.py", line 556, in start_stream self.sse = ClosableSSEClient(self.url, session=self.make_session(), build_headers=self.build_headers) File "/usr/local/lib/python3.5/dist-packages/pyrebase/pyrebase.py", line 518, in init super(ClosableSSEClient, self).init(*args, **kwargs) File "/home/pi/.local/lib/python3.5/site-packages/sseclient.py", line 39, in init self._connect() File "/usr/local/lib/python3.5/dist-packages/pyrebase/pyrebase.py", line 522, in _connect super(ClosableSSEClient, self)._connect() File "/home/pi/.local/lib/python3.5/site-packages/sseclient.py", line 47, in _connect self.resp = requester.get(self.url, stream=True, **self.requests_kwargs) File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 521, in get return self.request('GET', url, **kwargs) TypeError: request() got an unexpected keyword argument 'build_headers'

Please help, I am desperate..been struggling with this for hours

abvijaykumar avatar Apr 09 '18 23:04 abvijaykumar

Try passing token with the stream

my_stream = db.child("child1").child("child2").stream(command_handler, token)

vmanikes avatar Apr 10 '18 14:04 vmanikes

Thanks Venkat , what should i pass as token?

abvijaykumar avatar Apr 12 '18 02:04 abvijaykumar

def command_handler(message):
    print('event: ' + str(message["event"])) # put
    print('path: ' + str(message["path"])) # /-K7yGTTEp7O549EzTYtI
    print('data: ' + str(message["data"])) # {'title': 'Pyrebase', "body": "etc..."}

auth = firebase.auth()
user = auth.sign_in_with_email_and_password(email, password)
db = firebase.database()

my_stream = db.child("child1").child("child2").stream(command_handler, user['idToken'])

vmanikes avatar Apr 12 '18 02:04 vmanikes

@vmanikes tried ur suggestion, did not work :-(

abvijaykumar avatar Apr 13 '18 13:04 abvijaykumar

What error are you getting? Can you post the snippet?

vmanikes avatar Apr 13 '18 13:04 vmanikes

Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/usr/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.5/dist-packages/pyrebase/pyrebase.py", line 556, in start_stream self.sse = ClosableSSEClient(self.url, session=self.make_session(), build_headers=self.build_headers) File "/usr/local/lib/python3.5/dist-packages/pyrebase/pyrebase.py", line 518, in init super(ClosableSSEClient, self).init(*args, **kwargs) File "/home/pi/.local/lib/python3.5/site-packages/sseclient.py", line 39, in init self._connect() File "/usr/local/lib/python3.5/dist-packages/pyrebase/pyrebase.py", line 522, in _connect super(ClosableSSEClient, self)._connect() File "/home/pi/.local/lib/python3.5/site-packages/sseclient.py", line 47, in _connect self.resp = requester.get(self.url, stream=True, **self.requests_kwargs) File "/home/pi/.local/lib/python3.5/site-packages/requests/sessions.py", line 521, in get return self.request('GET', url, **kwargs) TypeError: request() got an unexpected keyword argument 'build_headers'

Here is the code I tried

import pyrebase

def stream_handler(message): print('event: ' + str(message["event"])) # put print('path: ' + str(message["path"])) # /-K7yGTTEp7O549EzTYtI print('data: ' + str(message["data"])) # {'title': 'Pyrebase', "body": "etc..."}

config = { "apiKey": "blablabla", "authDomain": "firebasedb", "databaseURL": "firebasedbURL", "storageBucket": "storage bucket" }

firebase = pyrebase.initialize_app(config)

auth = firebase.auth() user = auth.sign_in_with_email_and_password("email", "pass") db = firebase.database() #commands = db.child("commands").get() #print(zones.val())

my_stream = db.child("commands").child("arm").stream(stream_handler, user['idToken'])

abvijaykumar avatar Apr 13 '18 13:04 abvijaykumar

Quick point, this works good on mac, but when I try on raspberry pi, it does not work

abvijaykumar avatar Apr 13 '18 13:04 abvijaykumar

Can you do one check on Raspberry PI, check if the versions of following packages in your PI

gcloud==0.18.3
oauth2client==4.1.2
requests-toolbelt==0.8.0
python-jwt==2.0.1
pycrypto==2.6.1
pycryptodome==3.5.1

This is the config I use in my PI? If they differ, try upgrading packages on your PI

vmanikes avatar Apr 13 '18 13:04 vmanikes

yah, checked and updated all of them (everything was current except cloud)...but I am getting the exact same error

abvijaykumar avatar Apr 13 '18 13:04 abvijaykumar

I finally got it working..it works good with Python, when I try with Python3 it fails on raspberry pi (works fine in Mac though on Python3) :-)

abvijaykumar avatar Apr 14 '18 14:04 abvijaykumar

My other modules are failing, as they only run on Python3. Is there anyway I can get Pyrebase for Python3?

abvijaykumar avatar Apr 14 '18 14:04 abvijaykumar

I am having the similar problem too, I am working on windows

storyinvisible avatar Apr 08 '19 16:04 storyinvisible

I have the same error here, we are running based on Python3 at raspberry pi. Any ideia to solve?

emannuell avatar May 29 '19 14:05 emannuell

I solved this issue by going into sessions.py under the requests package and before the return statement of the get function (before line 521 in your case), add in this line kwargs.pop("build_headers")

This issue is occurring because build_headers is not a parameter for the request method. It accepts header instead of build_header. But in this case, the data type is still wrong. header is expecting a dictionary but build_header in this case is pointing to a function.

Hope this helps.

zeph1997 avatar Mar 03 '22 16:03 zeph1997