Hi again, I want to run my first flow linked to my...
# prefect-community
f
Hi again, I want to run my first flow linked to my local API and I am trying to run
client.create_project()
to create a project. But each time I get the following error :
Copy code
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: <http://xxx.xxx.xxx.xxx:4200/graphq>
My code :
Copy code
client = Client(api_server="<http://xxx.xxx.xxx.xxx:4200/graphql>")
client.create_project(project_name="weather")
I don't understand what port / URL I should put in
Client()
. Thank you for your help.
n
Hi @flavienbwk - how did you end up setting up Prefect Server? I know you mentioned that you intended to make some changes to a custom
docker-compose.yaml
f
Yes : so I've copied the Prefect docker-compose.yml without making any modification to it. I've just created a .env aside replicating the env variables from the compose file. You can see it here : https://github.com/flavienbwk/prefect-docker-compose/tree/main/server It's working well! I've managed to make it run for agents too. So now I want to create my first flow but I don't understand what parameter I should give to my flow to register it to my Prefect API (which is in a specific IP, not
localhost
).
🚀 1
n
Got it. In the case you'll need to provide that specific IP to the
api_server
, pointing it at the
:4200/graphql
endpoint. Another option is to set this in your local machine's
~/.prefect/config.toml
like this:
Copy code
[server]
endpoint="<http://your_ip:4200/graphql>"
Glad you got that up and working!!
f
Yeah !! Unfortunately that's exactly what I pass to Client() :
Copy code
Client(api_server="<http://192.168.254.1:4200/graphql>")
Getting :
Copy code
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: <http://192.168.254.1:4200/graphql>
😞
n
Can you confirm that that endpoint is available from your browser? You can just paste the address and you should see something like
GET query is missing
f
When going to
Copy code
<http://192.168.254.1:4200/graphql>
in my browser, I get the whole GraphQL interface
n
Ah ok perfect! That means it's running there. Are you running that code above from within any sort of container that might not have access to that endpoint?
f
I run my scrip from a container yes. However, it seems to have access as it returns the response immediately. When I change the endpoint to an inexistant IP, it just times out. Moreover, I use the same container architecture for my agents. And I've tried entering my container, curling the URL, and it returns
GET query missing.
n
Got it. Can you try running
prefect backend server
and then re-running your script?
🎉 1
f
I am getting another error now :
prefect.utilities.exceptions.ClientError: [{'message': 'Uniqueness violation.'
, I guess it worked ! 😄
Thank you!
n
Perfect!
You can set that permanently in your
~/.prefect/config.toml
like this:
Copy code
backend = "server"
f
OK thank you!
In the same idea, I don't see in the doc how I specify the endpoint of my API to register my task :
Copy code
flow.register(project_name="weather")
n
Did you set the
endpoint
in
~/.prefect/config.toml
as I mentioned above?
f
Yes, adding the
PREFECT_SERVER_ENDPOINT
env variable didn't have effect. Is it the way of doing ? By changing the env variables ? I'll investigate more if it is the case. What I don't understand is why I'm allowed to specify api_server=my_ip for Client(), but not for Flow()
n
Internally
flow.register
is creating an instance of
Client()
- I'm not sure the environment variable has an effect in that case
f
I confirm. I was forced to create the
config.toml
in order for my script to use a custom API endpoint. Is it intentional ?
n
Yes, that's correct - not all configuration options are read in from environment variables, particularly those meant for custom Server deployments.
f
Thank you for all your quick answers!
😄 1