https://prefect.io logo
Title
l

Luis Muniz

06/26/2020, 11:35 AM
Hi, is prefect-core API unsecured by default? I am trying to create an API token and get cryptic errors about JSON not being able to be parsed? The story is that I am trying to create a local agent by running
prefect agent start
This results in an error complaining about missing an API token.
prefect.utilities.exceptions.AuthorizationError: No agent API token provided.
When I then call
prefect auth create-token -n calypso -s RUNNER
I see the following error:
Traceback (most recent call last):
  File "/home/lmuniz/.local/bin/prefect", line 8, in <module>
    sys.exit(cli())
  File "/home/lmuniz/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/lmuniz/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/lmuniz/.local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/lmuniz/.local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/lmuniz/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/lmuniz/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/lmuniz/.local/lib/python3.8/site-packages/prefect/cli/auth.py", line 201, in create_token
    output = client.graphql(
  File "/home/lmuniz/.local/lib/python3.8/site-packages/prefect/client/client.py", line 213, in graphql
    result = <http://self.post|self.post>(
  File "/home/lmuniz/.local/lib/python3.8/site-packages/prefect/client/client.py", line 172, in post
    response = self._request(
  File "/home/lmuniz/.local/lib/python3.8/site-packages/prefect/client/client.py", line 334, in _request
    json_resp = response.json()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 897, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 518, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I have started prefect with the recommended
prefect server start
command and installed prefect with pip3.
$prefect diagnostics                                                                                                    
{
  "config_overrides": {},
  "env_vars": [],
  "system_information": {
    "platform": "Linux-5.4.0-7624-generic-x86_64-with-glibc2.29",
    "prefect_version": "0.12.1",
    "python_version": "3.8.2"
  }
}
Also: using the Dask executor ( created a local dask cluster)
export PREFECT__ENGINE__EXECUTOR__DEFAULT_CLASS="prefect.engine.executors.DaskExecutor"
export PREFECT__ENGINE__EXECUTOR__DASK__ADDRESS="<tcp://127.0.0.1:8786>"
i

itay livni

06/26/2020, 11:58 AM
@Luis Muniz What version of prefect are you on?
l

Luis Muniz

06/26/2020, 11:58 AM
"prefect_version": "0.12.1",
(hi)
I opened this bug yesteday
l

Luis Muniz

06/26/2020, 11:59 AM
I'm not connecting to prefect cloud
i

itay livni

06/26/2020, 11:59 AM
Hmm no secrets? nothing?
l

Luis Muniz

06/26/2020, 11:59 AM
I'm trying to run prefect independently, locally, to try to figure it out
just prefect-core
or is it not runnable independently of prefect cloud?
i

itay livni

06/26/2020, 12:01 PM
prefect is completely runnable independently. Its how most of my jobs are run..
l

Luis Muniz

06/26/2020, 12:01 PM
ok
i

itay livni

06/26/2020, 12:01 PM
Try installing version 0,12,0
l

Luis Muniz

06/26/2020, 12:01 PM
maybe I need to set up an environment variable to tell it to connect to the local API
?
I will try that
i

itay livni

06/26/2020, 12:03 PM
please try installing
pip install -U prefect==0.12.0
l

Luis Muniz

06/26/2020, 12:03 PM
thanks
i

itay livni

06/26/2020, 12:04 PM
Let me know if that works.
l

Luis Muniz

06/26/2020, 12:09 PM
yes, tokens are only for cloud deployments
By the way I have the same behavior with 0.12.0
Still no idea how to run an agent loccally though
OK @itay livni
prefect backend server
this was missing to tell my local setup that it is not useing prefec tcloud
after that I can start an agent
But yes: it seems that the prefect-core API is unauthenticated by default
c

Chris White

06/26/2020, 1:54 PM
Hi @Luis Muniz - you are confusing the locally served Prefect API with the Cloud API. The open source, locally served API has no authentication built in. The Prefect Cloud API does have authentication via JWT tokens. Your commands are attempting to hit the Prefect Cloud API and are running into errors because you haven’t logged in yet. If you’d like to use the secure API, I suggest logging in (for free) at https://cloud.prefect.io/ but if you want to use your locally hosted one, you should run
prefect backend server
first and avoid all auth-related commands
l

Luis Muniz

06/26/2020, 2:39 PM
Yes, it took me some time to realize that, thanks @Chris White. So am I right to think unless you use Prefect cloud you can't have secure access to the API ?
(using just prefect core)
c

Chris White

06/26/2020, 2:44 PM
Yup that’s essentially correct - we reserve the authentication layer for our hosted platform