question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to install package with custom pypi source

See original GitHub issue
  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

The steps to reproduce this bug is in the readme.

In short, I can’t install any package with a custom pypi source (https://pypi.douban.com/simple/). pip3 install celery -i https://pypi.douban.com/simple/ works find, so this should be a bug of poetry.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ocavuecommented, Jan 13, 2020

@thomaszdxsn

I have already found the reason of this issue as my comments above. We need not more discussion about the reason.

If you just want to avoid this issue, your can use https://mirrors.aliyun.com/pypi/simple.

1reaction
ocavuecommented, Jan 8, 2020

I did some little research. poetry use requests.get() to fetch packages from PyPI repository. request.get() will follow 301 redirection by default. The reason that poetry can’t install packages from https://pypi.douban.com/ is that Douban server return 418 I’m a teapot. I guess that this is an anti-scraping logic.

Use curl to visit pypi.douban.com. Get 301:

$ curl -v 'https://pypi.douban.com/simple/celery/'
...
< HTTP/1.1 301 Moved Permanently
...

Use requests to visit pypi.douban.com. Get 418:

In [1]: import requests

In [2]: requests.get('https://pypi.douban.com/simple/celery/')
Out[2]: <Response [418]>

In [3]:  requests.get('https://pypi.doubanio.com/simple/celery/')
Out[3]: <Response [200]>

In [4]: requests.get('https://pypi.douban.com/simple/celery/', headers={'user-agent': 'poetry'})
Out[4]: <Response [200]>

To avoid this 418 response, we can simply pass a user-agent into the request header.

Since adding a header in the request can fix this issue and I couldn’t see any disadvantage about this change, I can submit a PR to do it if you agree with me. @sdispater


Douban is one of the biggest Chinese companies that use Python as their main back-end language. The PyPI mirror their offer is very famous in the Chinese Python developer community.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why can't I install packages from PyPI with Pip? - Stack Overflow
When Pip only finds a "source package" on PyPI, and that source package contains native code, it tries to compile it, i.e. build...
Read more >
Troubleshooting PyPI package installation | Cloud Composer
Locate the pip error in Cloud Build logs · In Google Cloud console, go to the Build history page. Go to Build history...
Read more >
Error with pip install from PyPI in self hosted Gitlab - General
Prepare the following environment variables in your repo (Setting->CI/CD->Variables): PIP_URL, PIP_USERNAME, PIP_PASSWORD. Where PIP_URL is the ...
Read more >
Installing Packages - Python Packaging User Guide - Python.org
This section covers the basics of how to install Python packages. ... It does not to refer to the kind of package that...
Read more >
pip install - pip documentation v22.3.1
Install packages from: PyPI (and other indexes) using requirement specifiers. VCS project urls. Local project directories. Local or remote source archives.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found