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

Mismatched tag: line 117, column2 #29

Open
georgeboldeanu opened this issue Mar 10, 2022 · 0 comments
Open

Mismatched tag: line 117, column2 #29

georgeboldeanu opened this issue Mar 10, 2022 · 0 comments

Comments

@georgeboldeanu
Copy link

Hi!
I try to create an automated task to download a product every day. When i try to pass variables of present day and yesterday day i got this error!

---------------------------------------------------------------------------
ExpatError                                Traceback (most recent call last)
<ipython-input-60-126aef4a6a20> in <module>
      1 from motu_utils import motu_api
----> 2 motu_api.execute_request(MotuOptions(data_request_options_dict_automated))

D:\Python_VENVS\SST_OSTIA\lib\site-packages\motu_utils\motu_api.py in execute_request(_options, timeout)
    619                 log.debug("Asynchronous connection")
    620                 stopWatch.start('wait_request')
--> 621                 requestUrl = get_requestUrl(download_url, url_service, _options, **url_config)
    622 
    623                 if requestUrl is not None:

D:\Python_VENVS\SST_OSTIA\lib\site-packages\motu_utils\motu_api.py in get_requestUrl(dl_url, server, _options, **options)
    326     m = utils_http.open_url(dl_url, **options)
    327     responseStr = m.read()
--> 328     dom = minidom.parseString(responseStr)
    329     node = dom.getElementsByTagName('statusModeResponse')[0]
    330     status = node.getAttribute('status')

~\AppData\Local\Programs\Python\Python36\lib\xml\dom\minidom.py in parseString(string, parser)
   1966     if parser is None:
   1967         from xml.dom import expatbuilder
-> 1968         return expatbuilder.parseString(string)
   1969     else:
   1970         from xml.dom import pulldom

~\AppData\Local\Programs\Python\Python36\lib\xml\dom\expatbuilder.py in parseString(string, namespaces)
    923     else:
    924         builder = ExpatBuilder()
--> 925     return builder.parseString(string)
    926 
    927 

~\AppData\Local\Programs\Python\Python36\lib\xml\dom\expatbuilder.py in parseString(self, string)
    221         parser = self.getParser()
    222         try:
--> 223             parser.Parse(string, True)
    224             self._setup_subset(string)
    225         except ParseEscape:

ExpatError: mismatched tag: line 117, column 2

Here is my modified script after this thread on CMEMS forum: https://help.marine.copernicus.eu/en/articles/5211063-how-to-use-the-motuclient-within-python-environment-e-g-spyder

import motuclient
import getpass
import datetime
from datetime import datetime, timedelta
import os

class MotuOptions:
    def __init__(self, attrs: dict):
        super(MotuOptions, self).__setattr__("attrs", attrs)

    def __setattr__(self, k, v):
        self.attrs[k] = v

    def __getattr__(self, k):
        try:
            return self.attrs[k]
        except KeyError:
            return None


def motu_option_parser(script_template, usr, pwd, output_filename,out_dir,data_start,data_sfarsit):
    dictionary = dict(
        [e.strip().partition(" ")[::2] for e in script_template.split('--')])
    dictionary['variable'] = [value for (var, value) in [e.strip().partition(" ")[::2] for e in script_template.split('--')] if var == 'variable']  # pylint: disable=line-too-long
    for k, v in list(dictionary.items()):
        if v == '<OUTPUT_DIRECTORY>':
            dictionary[k] = out_dir
        if v == '<OUTPUT_FILENAME>':
            dictionary[k] = output_filename
        if v == '<USERNAME>':
            dictionary[k] = usr
        if v == '<PASSWORD>':
            dictionary[k] = pwd
        if v=='<date_min>':
            dictionary[k]= data_start
        if v=='<date_max>':
            dictionary[k]= data_sfarsit
        if k in ['longitude-min', 'longitude-max', 'latitude-min', 
                 'latitude-max', 'depth-min', 'depth-max']:
            dictionary[k] = float(v)
        if k in ['date_min', 'date_max']:
            dictionary[k] = v[1:-1]
        dictionary[k.replace('-','_')] = dictionary.pop(k)
    dictionary.pop('python')
    dictionary['auth_mode'] = 'cas'
    return dictionary

USERNAME =user
PASSWORD = pass

today= datetime.now()
yesterday= astazi1 - timedelta(days=1)


name=str(today)[:10]

data_min=today.strftime('%Y-%m-%d %H:%M:%S')
data_max=yesterday.strftime('%Y-%m-%d %H:%M:%S')
type(data_min)
print(data_max)

OUTPUT_FILENAME = name+'_SST.nc'

OUTPUT_DIRECTORY = "path"
script_template = 'python -m motuclient \
--motu https://nrt.cmems-du.eu/motu-web/Motu \
--service-id SST_GLO_SST_L4_NRT_OBSERVATIONS_010_001-TDS \
--product-id METOFFICE-GLO-SST-L4-NRT-OBS-SST-V2 \
--longitude-min 14 --longitude-max 44 \
--latitude-min 25 --latitude-max 66 \
--data_start <date_min>  --data_sfarsit <date_max>  \
--variable analysed_sst \
--out-dir <OUTPUT_DIRECTORY> --out-name <OUTPUT_FILENAME> \
--user <USERNAME>--pwd <PASSWORD>'
print(script_template)

data_request_options_dict_automated = motu_option_parser(script_template, USERNAME, PASSWORD, OUTPUT_FILENAME,OUTPUT_DIRECTORY, data_start, data_sfarsit)

data_request_options_dict_automated

from motu_utils import motu_api
motu_api.execute_request(MotuOptions(data_request_options_dict_automated)) `
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

1 participant