thinh-vu/vnstock

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Closed this issue · 3 comments

lỗi khi gọi hàm listing_companies()

Bạn vui lòng cung cấp thêm thông tin trường hợp lỗi của mình. Bạn có thể tham khảo lưu ý tại mục Discussion này #17


JSONDecodeError Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py:971, in Response.json(self, **kwargs)
970 try:
--> 971 return complexjson.loads(self.text, **kwargs)
972 except JSONDecodeError as e:
973 # Catch JSON-related errors and raise as requests.JSONDecodeError
974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File ~\AppData\Local\Programs\Python\Python310\lib\json_init_.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:

File ~\AppData\Local\Programs\Python\Python310\lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 """Return the Python representation of s (a str instance
334 containing a JSON document).
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()

File ~\AppData\Local\Programs\Python\Python310\lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 listing_companies()

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\vnstock\stock.py:43, in listing_companies()
39 """
40 This function returns the list of all available stock symbols.
41 """
42 url = 'https://fiin-core.ssi.com.vn/Master/GetListOrganization?language=vi'
---> 43 r = api_request(url)
44 df = pd.DataFrame(r['items']).drop(columns=['organCode', 'icbCode', 'organTypeCode', 'comTypeCode']).rename(columns={'comGroupCode': 'group_code', 'organName': 'company_name', 'organShortName':'company_short_name'})
45 return df

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\vnstock\stock.py:33, in api_request(url, headers)
32 def api_request(url, headers=headers):
---> 33 r = requests.get(url, headers).json()
34 return r

File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py:975, in Response.json(self, **kwargs)
971 return complexjson.loads(self.text, **kwargs)
972 except JSONDecodeError as e:
973 # Catch JSON-related errors and raise as requests.JSONDecodeError
974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Chi tiết lỗi đây ạ , mình làm theo ví dụ của bạn nhưng nó bị lỗi như này , các hàm khác thì sử dụng bình thường

Chào @thanhnx12
Hiện tại danh sách listing companies với mode='live' đang bị chặn truy cập từ bot bởi SSI nên không thể truy xuất trực tiếp dữ liệu live, bạn vẫn có thể chạy hàm listing_companies() theo mặc định để đọc dữ liệu từ github. Danh sách các công ty niêm yết không thay đổi thường xuyên nên đây là cách giải quyết đơn giản nhất. Mình sẽ cập nhật lại endpoint API mới khi có thể.