実現したいこと
以下の記事を参考に、同様の動作を行いたい。
https://qiita.com/easypatents39/items/d02706ce9e17a6f66869?utm_campaign=post_article&utm_medium=twitter&utm_source=twitter_share
問題点・相談したいこと
記事のコードを参考に実行すると、
以下のエラーが発生しました。
このエラーに関して疑問点が二つあります。
①エラーの理解として、
APIを通じて取得してきたファイル(json形式)が読み込めないと理解しているのですが、
それは正しいでしょうか?
②上記の記事では問題なく動いているのに対し、なぜこのようなエラーが生じるのでしょうか。
(上記の記事と同じ特許のファイルを要求しているため、返ってくるjsonファイルは同じものと考えています。
であれば、問題なく処理できるはずなのにできないのは、何か違う部分があるのでしょうか?)
APIやjsonファイルに関する理解が浅く、何か勘違いしている点があるかもしれません。
ご教授いただけますと幸いです。
発生している問題・エラーメッセージ
Python
1--------------------------------------------------------------------------- 2JSONDecodeError Traceback (most recent call last) 3File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\requests\models.py:971, in Response.json(self, **kwargs) 4 970 try: 5--> 971 return complexjson.loads(self.text, **kwargs) 6 972 except JSONDecodeError as e: 7 973 # Catch JSON-related errors and raise as requests.JSONDecodeError 8 974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError 9 10File D:\Anaconda_envs\envs\pip_env_2\lib\json\__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 11 343 if (cls is None and object_hook is None and 12 344 parse_int is None and parse_float is None and 13 345 parse_constant is None and object_pairs_hook is None and not kw): 14--> 346 return _default_decoder.decode(s) 15 347 if cls is None: 16 17File D:\Anaconda_envs\envs\pip_env_2\lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w) 18 333 """Return the Python representation of ``s`` (a ``str`` instance 19 334 containing a JSON document). 20 335 21 336 """ 22--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 23 338 end = _w(s, end).end() 24 25File D:\Anaconda_envs\envs\pip_env_2\lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx) 26 354 except StopIteration as err: 27--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 28 356 return obj, end 29 30JSONDecodeError: Expecting value: line 1 column 1 (char 0) 31 32During handling of the above exception, another exception occurred: 33 34JSONDecodeError Traceback (most recent call last) 35Cell In[14], line 2 36 1 from easy_patents.get_info import app_progress 37----> 2 progress_info = app_progress("2020-18475", reget_date=0) 38 39File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\easy_patents\get_info.py:586, in app_progress(case_number, law, reget_date) 40 554 def app_progress(case_number, law="patent", reget_date=1): 41 555 ''' 42 556 指定された特許出願番号に紐づく経過情報(優先権基礎情報、原出願情報、分割出願群情報を含まない)を取得する。 43 557 https://ip-data.jpo.go.jp/api_guide/api_reference.html#/%E7%89%B9%E8%A8%B1%E6%83%85%E5%A0%B1%E5%8F%96%E5%BE%97API/get-app_progress< 44 (...) 45 584 '特許庁' 46 585 ''' 47--> 586 return get_json(sys._getframe().f_code.co_name, case_number, law, reget_date) 48 49File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\easy_patents\get_info.py:547, in get_json(api_type, key, law, reget_date, convert) 50 545 else: 51 546 url = make_url(api_type, key, law=law, convert=convert) 52--> 547 json_data = get_api_info(url) 53 549 # 次回以降の処理のために保存 54 550 save_json(json_data, json_dir) 55 56File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\easy_patents\get_info.py:44, in get_api_info(url) 57 42 # 通信失敗などで取得エラーがありうるので、RETRY回までリトライする 58 43 for i in range(0, EASYPATENT_API_RETRY): 59---> 44 accesstoken = EASYPATENT_AUTHINFO.get_accesstoken() 60 45 header = { 61 46 "Host": EASYPATENT_HOST, 62 47 "Authorization": "Bearer " + accesstoken, 63 48 "User-Agent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/4E423F' 64 49 } 65 50 response = requests.get(url, headers=header) 66 67File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\easy_patents\auth_info.py:25, in AuthInfo.get_accesstoken(self) 68 24 def get_accesstoken(self): 69---> 25 self.refresh() 70 26 return self.access_token 71 72File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\easy_patents\auth_info.py:39, in AuthInfo.refresh(self) 73 37 now = datetime.now() 74 38 if now > self.refresh_expires_in: 75---> 39 self.get_token_by_username() 76 40 elif now > self.expires_in: 77 41 self.get_token_by_refresh_token() 78 79File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\easy_patents\auth_info.py:62, in AuthInfo.get_token_by_username(self) 80 60 now = datetime.now() 81 61 response = get_token(self.username, self.password, self.token_path) 82---> 62 self.update_tokens(now, response) 83 84File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\easy_patents\auth_info.py:44, in AuthInfo.update_tokens(self, now, response) 85 43 def update_tokens(self, now, response): 86---> 44 response = response.json() 87 45 # Configファイルのアップデート 88 46 self.config['AuthInfo']['access_token'] = response['access_token'] 89 90File D:\Anaconda_envs\envs\pip_env_2\lib\site-packages\requests\models.py:975, in Response.json(self, **kwargs) 91 971 return complexjson.loads(self.text, **kwargs) 92 972 except JSONDecodeError as e: 93 973 # Catch JSON-related errors and raise as requests.JSONDecodeError 94 974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError 95--> 975 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) 96 97JSONDecodeError: Expecting value: line 1 column 1 (char 0) 98 99
該当のソースコード
Python
1from easy_patents.update_authinfo import update_authinfo 2update_authinfo() 3#こちらでトークンパス、ユーザーネーム、パスワードを入力
Python
1#以下のコードで上記のエラーが発生 2from easy_patents.get_info import app_progress 3progress_info = app_progress("2020-8423", reget_date=0)
試したこと
このライブラリはすでに取得済みの情報を得るためにAPIにアクセスしないようにするため、
一定期間の間はキャッシュを用いるそうです。
仮想環境中のeasy-patentsのフォルダの中に、dataというフォルダが作られ、
今回の検索番号「2020008423」が作られ、中には「app_progress」というフォルダが
作られていましたが、中身は空でした。
最初はこれをみて、うまくアクセスできていない(IDやpassが間違っている)と思いましたが、
その場合は「KeyError: 'access_token'」が出力されるようです。
このような状態(フォルダ内にファイルがなく、JSONDecodeErrorが出る)になる理由が
分からず、困っています。
補足情報(FW/ツールのバージョンなど)
Python 3.10.8
easy-patents 1.0.10

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/05/07 12:28