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')


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

this article is not working can u give relavent one please

You're welcome. Happy scraping!

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

Thanks for the quick reply. I'll try and reply
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 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.
Login to post a comment