```$ prefect profile use development_service_accou...
# ask-community
s
Copy code
$ prefect profile use development_service_account
⠋ Connecting...
Error authenticating with Prefect Cloud using profile 'development_service_account'
No matter what I do I cannot connect to our Prefect 2.0 Cloud environment from my terminal. When I try to run a flow locally I get
Copy code
RuntimeError: Cannot create flow run. Failed to reach API at <https://api.prefect.cloud/api/accounts> ...
My account_id and workspace_id are correct, I have checked. I don't understand why I cannot connect
1
m
Hey @Sam Garvis I'm assuming so but do you have the prefect api key set in the profile configuration as well.
s
Yes I do
Copy code
$ prefect profile inspect
No name provided, defaulting to 'development_service_account'
PREFECT_API_URL='<https://api.prefect.cloud/api/accounts/aaaa/workspaces/aaaa>'
PREFECT_API_KEY='aaaa'
Both of those values are the correct values
k
What version of Prefect are you in?
s
2.0.3
Copy code
Version:             2.0.3
API version:         0.8.0
Python version:      3.10.4
Git commit:          2f1cf4ac
Built:               Fri, Aug 5, 2022 3:57 PM
OS/Arch:             darwin/x86_64
Profile:             development_service_account
Server type:         hosted
k
Could you try to run
Copy code
prefect cloud login --key xxx_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
again with a new profile to see if it works?
s
Copy code
$ prefect cloud login -k xxx_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Logged in to Prefect Cloud using profile 'garvis_try_again'.
Workspace is currently set to 'prizepicks/development-prizepicks-analytics-prefect2'. The workspace can be changed using `prefect cloud workspace set`.
Copy code
$ prefect profile use garvis_try_again
⠙ Connecting...
Error authenticating with Prefect Cloud using profile 'garvis_try_again'
Copy code
$ prefect cloud workspace set --workspace "prizepicks/development-prizepicks-analytics-prefect2"
Unable to authenticate. Please ensure your credentials are correct.
This is a profile that I made about an hour to retry this. Before I was using a service_account, but this is my user's api_key
k
So it seems like you first had the problem with connecting to the API, now you have the problem with the authentication. Can you create a new API key and try again? It could be that your API key was expired
s
Copy code
$ prefect cloud login -k xxx_XXXXXXXXXXXXXXXXXXXXXXXXX                                Select a Workspace:
│ > prizepicks/development-prizepicks-analytics-prefect2 │
│               prizepicks/prizepicks-analytics-prefect2 │

Creating a profile for this Prefect Cloud login. Please specify a profile name: garvis_api_again
Logged in to Prefect Cloud using profile 'garvis_api_again'.
Workspace is currently set to 'prizepicks/development-prizepicks-analytics-prefect2'. The workspace can be changed using `prefect cloud workspace set`.
Copy code
$ prefect profile use garvis_api_again
⠋ Connecting...
Error authenticating with Prefect Cloud using profile 'garvis_api_again'
Copy code
$ prefect cloud workspace set --workspace "prizepicks/development-prizepicks-analytics-prefect2"
Unable to authenticate. Please ensure your credentials are correct.
I've put never expire on all of the keys I've created, so I don't think that's the issue. I just created this key in the UI. And I think it instantly does not work. It's the same issue I've been seeing
k
It is weird that you saw that error. I just did a quick check and it is successfull
Copy code
$ prefect cloud login -k xxx_XXXXXXXXXXXXXXXXXXXXXXXXX

Creating a profile for this Prefect Cloud login. Please specify a profile name: test_cloud

Logged in to Prefect Cloud using profile 'test_cloud'.
Workspace is currently set to 'khuyenprefectio/test'. The workspace can be changed using `prefect cloud workspace set`.
Copy code
$ prefect profile use test_cloud                                 
⠙ Connecting...
Connected to Prefect Cloud using profile 'test_cloud'
Can you type
prefect config view
and see if you saw something like this?
Copy code
PREFECT_PROFILE='test_cloud'
PREFECT_API_KEY='xxx_XXXXXXXXXXXXXXXXXXXXXXXXX' (from profile)
PREFECT_API_URL='<https://api.prefect.cloud/api/accounts/XXX/workspaces/XXX>' (from profile)
s
🤦‍♂️🤦‍♂️🤦‍♂️Wow, I was just doing something stupid. I definitely checked the PREFECT_API_URL, and I thought I checked the PREFECT_API_KEY. I was overwriting PREFECT_API_KEY with an environment variable, so it said (from env). I think I checked PREFECT_API_KEY once before I pasted my env vars, and I then I pasted my env vars and wrote over it. Sorry for the trouble, but thank you for your help!
🎉 1
m
Glad you were able to get it sorted out 😄
1
No trouble at all we've all been there haha