콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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'


아바타
취소
작성자 베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
4
12월 23
46088
1
1월 23
3748
1
3월 24
6556
0
6월 22
2769
1
2월 21
2817