access Firestore serviceAccountKey.json file in code

Posted over 6 years ago by Ronak Raj Doongarwal

Post a topic
Answered
R
Ronak Raj Doongarwal

I have serviceAccountKey.json file in project root directory which I need to refer in this line of code of one of the python script.

cred = credentials.Certificate('\\serviceAccountKey.json')
firebase_admin.initialize_app(cred)

 but while deployment it fails giving error:

FileNotFoundError: [Errno 2] No such file or directory: '\\serviceAccountKey.json'

 Please help me how to refer to serviceAccountKey.json file in script which need to be deployed in scrapinghub .

NOTE: I also tried using 

os.getcwd() + "/serviceAccountKey.json"

and 

os.path.abspath(os.path.dirname(__file__)) + "/serviceAccountKey.json"

  

0 Votes

nestor

nestor posted over 6 years ago Admin Best Answer

pkgutil already reads the content. I guess this could work:


data = os.path.join(os.path.dirname(__file__), '../resources/file.json')

1 Votes


8 Comments

Sorted by
S

Sergey Geron posted over 1 year ago Admin

Hi Yeshwanth, this is Sergey Geron, Business Analyst at Zyte.

Thank you for reaching out through our Forum. 


We have changed our domain from support.scrapinghub.com to support.zyte.com

Check out the article here - https://support.zyte.com/support/solutions/articles/22000200416-deploying-non-code-files

0 Votes

Y

Yeshwanth Bheempad posted over 1 year ago

this article is not working can u give relavent one please

0 Votes

nestor

nestor posted over 6 years ago Admin

You're welcome. Happy scraping!

0 Votes

R

Ronak Raj Doongarwal posted over 6 years ago

@nestor Thanks for helping. It worked. Deployed my first spider.

0 Votes

R

Ronak Raj Doongarwal posted over 6 years ago

Thanks for the quick reply. I'll try and reply

0 Votes

nestor

nestor posted over 6 years ago Admin Answer

pkgutil already reads the content. I guess this could work:


data = os.path.join(os.path.dirname(__file__), '../resources/file.json')

1 Votes

R

Ronak Raj Doongarwal posted over 6 years ago

Thanks I have already tried this solution but didn't worked for me. But certificate funtion doesn't take file contents, it takes filename as parameter. Please suggest something to pass file as parameter.

0 Votes

nestor

nestor posted over 6 years ago Admin

0 Votes

Login to post a comment