Start a new topic
Answered

access Firestore serviceAccountKey.json file in code

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"

  


Best Answer

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


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


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.
Answer

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


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


1 person likes this
Thanks for the quick reply. I'll try and reply

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

You're welcome. Happy scraping!

this article is not working can u give relavent one please

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

Login to post a comment