cartoframes icon indicating copy to clipboard operation
cartoframes copied to clipboard

Error publishing map

Open ncarboni opened this issue 2 years ago • 0 comments

I am having a bit of trouble trying to export or publish a map I created with cartoframes. The ideal possibility would be to export in HTML directly, but my udnerstanding is that it is not possible (please correct me if I am wrong). Alternatevely, I thought to publish it on carto, however I am getting the "UnauthorizedErrorException: Access denied".

What I am doing:

I simply created a map, created a custom API key, set the credentials in a json file following the form:

{
  "username": "MY_USERNAME",
  "api_key": "API_KEY"
}

and use the funciton publish without password. Here's the code:

from cartoframes.viz import Map, Layer, size_bins_style
from cartoframes.auth import set_default_credentials

set_default_credentials('creds.json')
map_vc = Map(Layer(gdf, size_bins_style('City_number')))
map_vc.publish(
    name='map_test',
    password=None,
    if_exists='replace'
)

However I get the error "UnauthorizedErrorException: Access denied"

---------------------------------------------------------------------------
UnauthorizedErrorException                Traceback (most recent call last)
Input In [116], in <module>
      4 set_default_credentials('creds.json')
      5 map_vc = Map(Layer(gdf, size_bins_style('City_number')))
----> 6 map_vc.publish(
      7     name='map_public_table',
      8     password=None,
      9     if_exists='replace'
     10 )

File ~/.local/lib/python3.8/site-packages/cartoframes/utils/metrics.py:110, in send_metrics.<locals>.decorator_func.<locals>.wrapper_func(*args, **kwargs)
    108 @functools.wraps(func)
    109 def wrapper_func(*args, **kwargs):
--> 110     result = func(*args, **kwargs)
    112     if get_metrics_enabled():
    113         extra_metrics_data, server_domain_tld = build_extra_metrics_data(func, *args, **kwargs)

File ~/.local/lib/python3.8/site-packages/cartoframes/viz/map.py:220, in Map.publish(self, name, password, credentials, if_exists, maps_api_key)
    217 self._publisher.set_layers(self.layers, maps_api_key)
    219 html = self._get_publication_html(name)
--> 220 return self._publisher.publish(html, name, password, if_exists)

File ~/.local/lib/python3.8/site-packages/cartoframes/viz/kuviz.py:44, in KuvizPublisher.publish(self, html, name, password, if_exists)
     43 def publish(self, html, name, password, if_exists='fail'):
---> 44     self.kuviz = _create_kuviz(html, name, self._auth_client, password, if_exists)
     45     return kuviz_to_dict(self.kuviz)

File ~/.local/lib/python3.8/site-packages/cartoframes/viz/kuviz.py:94, in _create_kuviz(html, name, auth_client, password, if_exists)
     92     return kmanager.create(html=html, name=name, password=password, if_exists=if_exists)
     93 except Exception as e:
---> 94     manage_kuviz_exception(e, name)

File ~/.local/lib/python3.8/site-packages/cartoframes/viz/kuviz.py:131, in manage_kuviz_exception(error, name)
    127 if str(error) == 'Public map quota exceeded':
    128     raise PublishError("You have reached the limit for the number of maps you can create with your account. "
    129                        "Upgrade your account or delete some of your previous maps to be able to create new ones.")
--> 131 raise error

File ~/.local/lib/python3.8/site-packages/cartoframes/viz/kuviz.py:92, in _create_kuviz(html, name, auth_client, password, if_exists)
     89 kmanager = _get_kuviz_manager(auth_client)
     91 try:
---> 92     return kmanager.create(html=html, name=name, password=password, if_exists=if_exists)
     93 except Exception as e:
     94     manage_kuviz_exception(e, name)

File ~/.local/lib/python3.8/site-packages/carto/kuvizs.py:80, in KuvizManager.create(self, html, name, password, if_exists)
     63 def create(self, html, name, password=None, if_exists=IF_EXISTS_FAIL):
     64     """
     65     Creates a Kuviz.
     66 
   (...)
     78                 of the new Kuviz
     79     """
---> 80     return super(KuvizManager, self).create(data=html, name=name, password=password, if_exists=if_exists)

File ~/.local/lib/python3.8/site-packages/pyrestcli/resources.py:321, in Manager.create(self, **kwargs)
    319 resource = self.resource_class(self.client)
    320 resource.update_from_dict(kwargs)
--> 321 resource.save(force_create=True)
    323 return resource

File ~/.local/lib/python3.8/site-packages/pyrestcli/resources.py:214, in Resource.save(self, force_create, fields)
    212     return self.send(self.get_resource_endpoint(), "put", headers=http_headers, json=json, data=data)
    213 else:
--> 214     return self.send(self.get_collection_endpoint(), "post", headers=http_headers, json=json, data=data)

File ~/.local/lib/python3.8/site-packages/pyrestcli/resources.py:161, in Resource.send(self, url, http_method, **client_args)
    153 """
    154 Make the actual request to the API, updating the resource if necessary
    155 :param url: Endpoint URL
   (...)
    158 :return:
    159 """
    160 response = super(Resource, self).send(url, http_method, **client_args)
--> 161 response_data = self.client.get_response_data(response, self.Meta.parse_json)
    163 # Update Python object if we get back a full object from the API
    164 try:

File ~/.local/lib/python3.8/site-packages/pyrestcli/auth.py:51, in BaseAuthClient.get_response_data(self, response, parse_json)
     49         return response.content
     50 else:
---> 51     raise BaseException.create(response)

File ~/.local/lib/python3.8/site-packages/pyrestcli/exceptions.py:38, in BaseException.create(response)
     36 error = ERRORS.get(status_code, 'BaseException')
     37 klass = getattr(sys.modules[__name__], error)
---> 38 raise klass(message, status_code, headers, reason, url)

UnauthorizedErrorException: Access denied

Using the master password, I have the same issue

Any idea why it is happening? I am on a free plan, it is maybe due to that?

ncarboni avatar Apr 27 '22 13:04 ncarboni