3

I don't know how to Summarize or Format the problem, I am providing the error


Traceback (most recent call last): File "push.py", line 1, in from pyrebase import pyrebase File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyrebase__init__.py", line 1, in from .pyrebase import initialize_app File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyrebase\pyrebase.py", line 17, in from oauth2client.service_account import ServiceAccountCredentials File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauth2client\service_account.py", line 25, in from oauth2client import client File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauth2client\client.py", line 45, in from oauth2client import crypt File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauth2client\crypt.py", line 55, in from oauth2client import _pycrypto_crypt File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\oauth2client_pycrypto_crypt.py", line 17, in from Crypto.PublicKey import RSA File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pycrypto-2.6.1-py3.7-win32.egg\Crypto\PublicKey\RSA.py", line 75, in from Crypto.Util.number import getRandomRange, bytes_to_long, long_to_bytes File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pycrypto-2.6.1-py3.7-win32.egg\Crypto\Util\number.py", line 139 value = 2L ** (N-1) # Ensure high bit is set ^ SyntaxError: invalid syntax


I had errors installing Pyrebase so I am currently using Pyrebase4 I also tried installing PyCryptoDome and then installing Pyrebase manually after configuring to avoid versioning error This is my code:

import pyrebase

config={keys and all go here}

firebase=pyrebase.initialize_app(config)
db=firebase.database()

db.child("names").push({"name":"Abhinav"})

Expected to push data to Firebase

  • 2
    If you're getting a syntax error in a third-party library, it usually means you're using a different version of Python than the library is compatible with. – Barmar Aug 02 '19 at 21:36
  • @Barmar I agree. I spent some time looking at the library's [github repo](https://github.com/dlitz/pycrypto), hoping to confirm that it wasn't compatible with Python 3 - but I couldn't see any sign of this, or see any syntax error near the highlighted line. However it became apparent that the library has not been maintained for 5 years, so it's probably not a good idea to be using it anyway. – Robin Zigmond Aug 02 '19 at 21:43
  • 1
    In fact, it specifically says **PyCrypto is written and tested using Python version 2.1 through 3.3.** – Barmar Aug 02 '19 at 21:46
  • Could you paste the traceback with proper formatting? There a `^` that points to where the invalid syntax is, but it's not helpful when you wrap all the lines. – Barmar Aug 02 '19 at 21:46
  • missed that, thanks @Barmar. (I didn't realise changes of 3.x version could cause syntax errors though, just possibly different APIs in some modules.) – Robin Zigmond Aug 02 '19 at 21:50
  • The problem is `2L`. That syntax isn't supported in Python 3.6. In Python 3, integers have unlimited precision, there's no distinction between `int` and `long`. – Barmar Aug 02 '19 at 21:50
  • Maybe earlier 3.x versions supported it for backward compatibility, which is why it worked in their testing with 3.3. – Barmar Aug 02 '19 at 21:51
  • It looks like they had a [thing](https://github.com/dlitz/pycrypto/blob/7acba5f3a6ff10f1424c309d0d34d2b713233019/setup.py#L70) that was supposed to run 2to3 on the code, but it doesn't seem to have triggered properly. – user2357112 Aug 02 '19 at 21:57

3 Answers3

10

if you have installed pyrebase (v3) and is not working just do

pip3 install pyrebase4
gamingflexer
  • 250
  • 3
  • 5
1

Just use Pyrebase4 instead of pyrebase 3

Hakun
  • 357
  • 3
  • 10
0

Change

value = 2L ** (N-1)

to

value = 2 ** (N-1)

Python 3 doesn't have long integers, all integers are unlimited precision.

You may need to search the rest of the code for other long integers. You can use a regexp \dL to find them.

Barmar
  • 741,623
  • 53
  • 500
  • 612