`huggingface_hub.upload_file` returns a 404 error

Good day,

I am trying to upload files to a HF dataset programmatically. The sequence of my actions is as follows:

huggingface_hub.create_repo(
        name=dataset_slug,
        private=True,
        repo_type="dataset"
)

huggingface_hub.upload_file(
            path_or_fileobj="{LOCAL_DIRECTORY}/README.md",
            path_in_repo="README.md",
            repo_id="{USERNAME}/" + dataset_slug
)

The second command fails with:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/api/{USERNAME}/{DATASET_SLUG}/upload/main/README.md

USERNAME, LOCAL_DIRECTORY, and DATASET_SLUG are replaced appropriately. Am I doing something wrong, or is it a bug on HuggingFace’s end?

Hi there! upload_file also has a parameter which is repo_type. You should set it to “dataset” as well for this to work.

2 Likes