flit icon indicating copy to clipboard operation
flit copied to clipboard

400 Bad Request when uploading to Test PyPi

Open Grissess opened this issue 1 year ago • 2 comments

Hello! I'm not sure if this is on you or on Test PyPI, but I was having trouble publishing (experimentally) a local build thereto:

$ flit publish --repository testpypi
...
Traceback (most recent call last):
  File "/usr/host/bin/flit", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/x86_64-pc-linux-gnu/lib/python3.12/site-packages/flit/__init__.py", line 200, in main
    main(args.ini_file, repository, args.pypirc, formats=set(args.format or []),
  File "/usr/x86_64-pc-linux-gnu/lib/python3.12/site-packages/flit/upload.py", line 277, in main
    do_upload(built.wheel.file, built.wheel.builder.metadata, pypirc_path, repo_name)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.12/site-packages/flit/upload.py", line 252, in do_upload
    upload_file(file, metadata, repo)
  File "/usr/x86_64-pc-linux-gnu/lib/python3.12/site-packages/flit/upload.py", line 245, in upload_file
    resp.raise_for_status()
  File "/usr/x86_64-pc-linux-gnu/lib/python3.12/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://test.pypi.org/legacy/

I checked around a few times to be confident that this ~/.pypirc seemed valid:

[distutils]
index-servers =
  pypi
  testpypi

[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__

[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__

(I'm inserting the tokens out of band :)

After a few times of suspecting it was an auth error or some other shenanigan, it (to my surprise) succeeded when I uploaded with flit publish to main PyPI. Of course, I'd rather have tested that the release went alright (even though it seems to have), so this isn't an ideal situation.

EDIT: To be sure, this seems very rare--no Internet search I consulted had the exact string Bad Request for url: https://test.pypi.org/legacy/ return any results. It certainly doesn't seem to be a dupe of #455!

Grissess avatar Oct 23 '24 18:10 Grissess

Hmm, that's interesting. Is it possible the package you were trying to upload was already there on TestPyPI, and it was refusing to accept the same package twice? I'd hope it would give a clearer error message for that, but it's possible. I don't think Flit should do anything different for Test PyPI & regular PyPI, other than the different URL.

takluyver avatar Oct 24 '24 09:10 takluyver

I didn't actually change any details before it uploaded (successfully!) to main PyPI--that's not to say it couldn't have already been on TestPyPI, although, if memory serves, I failed to upload it due to authentication issues the first couple tries :)

You're right, if that was the issue, I'd hope the error message would have been better. I could nonetheless try to repro, for what it's worth...

Grissess avatar Oct 26 '24 05:10 Grissess