Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
2958 Visualizzazioni

i wanted to add the updated version ( FCM APIs to HTTP v1 ) of fcm  api which is like this 

headers = {
"Authorization": "Bearer " + _get_access_token(),
"Content-Type": "application/json; UTF-8"
}
response = requests.post(
"https://fcm.googleapis.com/v1/projects/my_project_id/messages:send",
data=json.dumps(message),
headers=headers

here is code which i have included to get the access token 

def _get_access_token():
"""Retrieve a valid access token that can be used to authorize requests.
:return: Access token.
"""
credentials = service_account.Credentials.from_service_account_file(
'service_account_key.json', scopes=SCOPES)
request = google.auth.transport.requests.Request()
credentials.refresh(request)
return credentials.token

print(_get_access_token())
 I have added the service account json to same directory 
service_account_key.json
 directory look like this 
module
|-- models
|   |-- service_account_key.json
|-- |---get_token_from_key.py | |-- __init__.py |-- other_module_files..

 i,m getting this error 


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/modules/_service_account_info.py", line 78, in from_filename
    with io.open(filename, "r", encoding="utf-8") as json_file:
FileNotFoundError: [Errno 2] No such file or directory: 'service_account_key.json'


Avatar
Abbandona
Autore Risposta migliore

so by using the  following code 


from odoo.modules.module import get_module_resource


 Service_account_key= get_module_resource('mymodule', 'directory (like models or controllers or static/src/ ),  'filename(like in my case'service_account_key.json' )')


it works
or you can refer this for clearancehttps://www.odoo.com/forum/help-1/read-file-contents-on-module-location-156533

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
4
dic 23
45679
1
gen 23
3524
1
mar 24
6335
0
giu 22
2652
1
feb 21
2684