Hi Guys, I am trying to use Github Storage, but ru...
# ask-community
s
Hi Guys, I am trying to use Github Storage, but run into the following error:
Copy code
Failed to load and execute Flow's environment: BadCredentialsException(401
Any advice how to proceed to solve this error?
k
Hi @Saksham Dixit, how are you storing the Git credentials at the moment? Does the place you’re running the agent on have these credentials stores?
s
passing them along with the docker agent
prefect agent docker start --env PREFECT__CONTEXT__SECRETS__GITHUB_ACCESS_TOKEN="token"
k
This looks right to me, can you try passing it through DockerRun to see if that works?
Could you try removing the quotes around “token”? Ignore this. It loads right for me
Are you sure this token has access to the repo? Because this error seems to mean the credentials are invalid rather than not found.
s
The credentials look right .
k
I’ll try to replicate on my end
Can you try if this code snippet works with your token?
Copy code
from github import Github

# First create a Github instance:

# using an access token
g = Github("token")
repo = g.get_repo("usename/repo_name")
contents = repo.get_contents("")
for content_file in contents:
    print(content_file)
Insert repo and token there
s
sure thanks Kevin let me try this out
k
I get the same error as you when I use a bad token
s
thanks for this Kevin if while creating a github instance I put base_url:
Copy code
from github import Github
# First create a Github instance:
# using an access token
g = Github("token",base_url="")
repo = g.get_repo("usename/repo_name")
contents = repo.get_contents("")
for content_file in contents:
    print(content_file)
I get an error
Copy code
assert o.hostname in [
AssertionError: None
If I dont put the base url parameter I get the bad credentials error
k
Oh you mean you have your own hosted Github?
Try
g = Github(base_url="https://{hostname}/api/v3", login_or_token="token")
?
Do you have the base_url in your Storage in Prefect?
s
when I do
g = Github(base_url="https://{hostname}/api/v3", login_or_token="token")
I get the contents
thanks i was using base_url but wasnt putting it in `"https://{hostname}/api/v3"`format
👍 1