https://prefect.io logo
f

flavienbwk

10/09/2020, 8:45 PM
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

nicholas

10/09/2020, 8:51 PM
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

flavienbwk

10/09/2020, 8:56 PM
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

nicholas

10/09/2020, 9:00 PM
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

flavienbwk

10/09/2020, 9:07 PM
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

nicholas

10/09/2020, 9:09 PM
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

flavienbwk

10/09/2020, 9:10 PM
When going to
Copy code
<http://192.168.254.1:4200/graphql>
in my browser, I get the whole GraphQL interface
n

nicholas

10/09/2020, 9:18 PM
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

flavienbwk

10/09/2020, 9:25 PM
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

nicholas

10/09/2020, 9:27 PM
Got it. Can you try running
prefect backend server
and then re-running your script?
🎉 1
f

flavienbwk

10/09/2020, 9:28 PM
I am getting another error now :
prefect.utilities.exceptions.ClientError: [{'message': 'Uniqueness violation.'
, I guess it worked ! 😄
Thank you!
n

nicholas

10/09/2020, 9:29 PM
Perfect!
You can set that permanently in your
~/.prefect/config.toml
like this:
Copy code
backend = "server"
f

flavienbwk

10/09/2020, 9:31 PM
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

nicholas

10/09/2020, 9:55 PM
Did you set the
endpoint
in
~/.prefect/config.toml
as I mentioned above?
f

flavienbwk

10/09/2020, 9:57 PM
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

nicholas

10/09/2020, 10:02 PM
Internally
flow.register
is creating an instance of
Client()
- I'm not sure the environment variable has an effect in that case
f

flavienbwk

10/09/2020, 10:08 PM
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

nicholas

10/09/2020, 10:10 PM
Yes, that's correct - not all configuration options are read in from environment variables, particularly those meant for custom Server deployments.
f

flavienbwk

10/09/2020, 10:12 PM
Thank you for all your quick answers!
😄 1