Hi, I am getting this error when trying to start m...
# ask-community
m
Hi, I am getting this error when trying to start my local agent. I've already authenticated using my token in the cli.
Copy code
RuntimeError: Error while contacting API at <https://api.prefect.io>
m
Hello Medison! What version of Prefect are you using? Can you set this environment variable
export PREFECT__CLOUD__AGENT__LEVEL=DEBUG
and run the agent again?
m
How do I check the version using cli?
When I set that I get same error and it doesn't tell me version
m
Can you run
prefect version
?
m
0.14.22
m
and
prefect diagnostics
please?
m
Copy code
{
  "config_overrides": {},
  "env_vars": [
    "PREFECT__CLOUD__AGENT__LEVEL"
  ],
  "system_information": {
    "platform": "macOS-10.15.7-x86_64-i386-64bit",
    "prefect_backend": "cloud",
    "prefect_version": "0.14.22",
    "python_version": "3.9.6"
  }
}
m
Can you upgrade prefect
pip install --upgrade prefect
and run your agent with service account key
prefect agent local start -k <your service account key>
m
That works but I did update the flow I was running and added another and I am not seeing the changes reflected on UI
How can I update the flow with the most recent code?
I also changed file paths, not sure if that affects things
m
I'm glad that worked. As I understand, you updated the code for the flow, then you registered a new version of this flow with Prefect Cloud by
python <file_with_flow>.py
, right? Can you check in flow dashboard in UI that a new version of the flow showed up? It's in the top right corner
m
Ah no I didn’t
That’s probably the issue, I just ran the agent right away
I just use that command to register it?
m
I see, so register will reregister the flow if you change the flow metadata, but if you for example made a little change in the code of the task, you need to force reregistering by:
prefect register --force ...
m
And then the name of the flow?
what about deleting a flow?
m
yeah, you can run like this for example:
prefect register --path flow.py --project my-project --force
There are different ways to delete flow, you can do it in UI (flow dashboard), or interactive API (also UI, but using graphql query), or programmatically using graphql too
m
Got it- one last question. I ahve another flow that I've registered in my file using the below command but it doesn't show up on the UI. Do I need to also use the run command for it to show up on the UI?
web_sessions_flow.register(project_name="Winc")
m
Yes, every time you write a flow, you need to register it with backend, in this case you can simply run that command, and it should show up in UI 👍
m
Hmm for some reason is it still not showing up on UI even after registering it
m
Hmm, interesting 🤔 do you see any flow URL/id after you run register command?
did you use
--force
flag with that command?
m
Yeah I did
I run the register command on the UI? It’s in the file
m
You have a flow with
web_sessions_flow.register(project_name="Winc")
line saved in the file <name_of_the_file>.py and you ran
prefect register --project XXX --path <name_of_the_file>.py --force
and it doesn't show up in the UI, right? Can you try to run
python <name_of_the_file>.py
and check if the flow is in UI now?
m
still nothing
the version of the other flow I have just keeps changing
do they have to be in seperate files?
right now both flows are in the same file
m
Yes, can you add those flows in separate files, and try to register again, and let me know if it still doesn't show up in UI?
m
now it is working
🙌 1
so is it best practices to create a file per flow?
it just seems kinda redundant since I reuse the same code a lot
m
You actually can use imports, multiple flows, not sure why it didn't work for you. You can paste redacted flows here, and I can take a look
m
Also how do I make it so every time I run my flow it doesn't start a new local agent? Everytime I just try to update the code it starts a local agent
m
I guess you have a code block somewhere which starts a local agent, can you remove/comment it?
m
Ah ok, so the
.run_agent
with the token id creates a local agent every time it is ran?
How do I register a flow with my ecs agent?
m
yeah, it starts a new process with the agent
you can do it using different approaches. The easiest way is to spin up the ecs agent and create the flow with ECS run_config, and then use the command we discussed above (
prefect register ...
or
python <file>.py
)