Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpatError: syntax error: line 1, column 0 #31

Open
matteodefelice opened this issue Jun 3, 2024 · 5 comments
Open

ExpatError: syntax error: line 1, column 0 #31

matteodefelice opened this issue Jun 3, 2024 · 5 comments

Comments

@matteodefelice
Copy link

Today I can't use the APIs. If I type (after setting up client):

start_date = '2020-01-01'
end_date = '2020-01-01 1:30'
df_B1610 = client.get_B1610(start_date, end_date)

I get:

B1610:   0%|                                                                                     | 0/3 [00:02<?, ?it/s]
---------------------------------------------------------------------------
ExpatError                                Traceback (most recent call last)
Input In [6], in <cell line: 1>()
----> 1 df_B1610 = client.get_B1610(start_date, end_date)

File ~\miniconda3\envs\pydef\lib\site-packages\ElexonDataPortal\api.py:665, in Client.get_B1610(self, start_date, end_date, NGCBMUnitID)
    650 def get_B1610(
    651     self,
    652     start_date: str = '2020-01-01',
    653     end_date: str = '2020-01-01 1:30',
    654     NGCBMUnitID: str='*',
    655 ):
    656     """
    657     Actual Generation Output per Generation Unit
    658
   (...)
    662         NGCBMUnitID (str)
    663     """
--> 665     df = orchestrator.query_orchestrator(
    666         method = 'get_B1610',
    667         api_key = self.api_key,
    668         n_attempts = self.n_retry_attempts,
    669         request_type = 'SP_and_date',
    670         kwargs_map = {'date': 'SettlementDate', 'SP': 'Period'},
    671         func_params = ['APIKey', 'date', 'SP', 'NGCBMUnitID', 'ServiceType'],
    672         start_date = start_date,
    673         end_date = end_date,
    674         NGCBMUnitID = NGCBMUnitID,
    675         non_local_tz = self.non_local_tz
    676     )
    678     return df

File ~\miniconda3\envs\pydef\lib\site-packages\ElexonDataPortal\dev\orchestrator.py:413, in query_orchestrator(method, api_key, request_type, kwargs_map, func_params, start_date, end_date, n_attempts, non_local_tz, **kwargs)
    410 assert request_type in request_type_to_func.keys(), f"{request_type} must be one of: {', '.join(request_type_to_func.keys())}"
    411 request_func = request_type_to_func[request_type]
--> 413 df = request_func(
    414     method=method,
    415     api_key=api_key,
    416     n_attempts=n_attempts,
    417     **kwargs
    418 )
    420 df = df.reset_index(drop=True)
    422 if (non_local_tz is not None) and ('local_datetime' in df.columns):

File ~\miniconda3\envs\pydef\lib\site-packages\ElexonDataPortal\dev\orchestrator.py:78, in SP_and_date_request(method, kwargs_map, func_params, api_key, start_date, end_date, n_attempts, **kwargs)
     75 missing_kwargs = list(set(func_params) - set(['SP', 'date'] + list(kwargs.keys())))
     76 assert len(missing_kwargs) == 0, f"The following kwargs are missing: {', '.join(missing_kwargs)}"
---> 78 r = retry_request(raw, method, kwargs, n_attempts=n_attempts)
     80 df_SP = utils.parse_xml_response(r)
     81 df = pd.concat([df, df_SP])

File ~\miniconda3\envs\pydef\lib\site-packages\ElexonDataPortal\dev\orchestrator.py:30, in retry_request(raw, method, kwargs, n_attempts)
     28         attempts += 1
     29         if attempts == n_attempts:
---> 30             raise e
     32 return r

File ~\miniconda3\envs\pydef\lib\site-packages\ElexonDataPortal\dev\orchestrator.py:25, in retry_request(raw, method, kwargs, n_attempts)
     23 try:
     24     r = getattr(raw, method)(**kwargs)
---> 25     utils.check_status(r)
     26     success = True
     27 except Exception as e:

File ~\miniconda3\envs\pydef\lib\site-packages\ElexonDataPortal\dev\utils.py:26, in check_status(r)
     25 def check_status(r):
---> 26     r_metadata = xmltodict.parse(r.text)['response']['responseMetadata']
     28     if r_metadata['httpCode'] == '204':
     29         warn(f'Data request was succesful but no content was returned')

File ~\miniconda3\envs\pydef\lib\site-packages\xmltodict.py:378, in parse(xml_input, encoding, expat, process_namespaces, namespace_separator, disable_entities, process_comments, **kwargs)
    376     parser.Parse(b'',True)
    377 else:
--> 378     parser.Parse(xml_input, True)
    379 return handler.item

ExpatError: syntax error: line 1, column 0
@leoniewgnr
Copy link

same error here

@yanglu3406
Copy link

Same issue - does anyone know what's going on?

@yanglu3406
Copy link

yanglu3406 commented Jul 22, 2024

From a dig around - I think the https://api.bmreports.com/ API is no longer available - getting this response from any calls to it.

<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>

The Elexon API page refers to: https://data.elexon.co.uk/bmrs/api/v1/ and I can confirm this returns data as expected.

This library may need to be updated to reflect this change?

@yanglu3406
Copy link

Actually - just spotted that this was flagged ages ago, with a new library made for the new API

#28

@peterdudfield
Copy link
Contributor

yea, we've just made a new repo - https://github.com/openclimatefix/Elexonpy
Please let me know if this is useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants