# PyPi Upload with API token not working

**URL:** <https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338>\
**Category:** Deployment\
**Tags:** pypi\
**Created:** [October 7, 2019, 4:09pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338 "2019-10-07T16:09:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BY-jk](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@BY-jk](https://travis-ci.community/u/BY-jk)\
**Post date:** [October 7, 2019, 4:09pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/1 "2019-10-07T16:09:40Z")

</div>

I recently switched to API token based authentication for uploading packages to PyPi.

As the tokens are too long to be encrypted using travis-cli, I set the PYPI\_PASSWORD environment variable instead. This relies on this feature: [https://github.com/travis-ci/dpl/blob/v1.10.12/lib/dpl/provider/pypi.rb#L12](https://github.com/travis-ci/dpl/blob/v1.10.12/lib/dpl/provider/pypi.rb#L12) referenced in this issue [https://github.com/travis-ci/travis.rb/issues/221](https://github.com/travis-ci/travis.rb/issues/221)

This worked like a charm in my first tagged build: [https://travis-ci.org/blue-yonder/sqlalchemy\_exasol/jobs/591866904#L924](https://travis-ci.org/blue-yonder/sqlalchemy_exasol/jobs/591866904#L924)

But for the second tagged build, I ran into the following issue: [https://travis-ci.org/blue-yonder/sqlalchemy\_exasol/jobs/592508182#L927](https://travis-ci.org/blue-yonder/sqlalchemy_exasol/jobs/592508182#L927)

“missing PyPI password”

I dropped the old token and issued a new one at PyPi, added it again to the environment. Still no success when rerunning that build.

I looked at the diff between the two tags (2.0.7 and 2…0.8) of my repo, but nothing relating to Travis: [https://github.com/blue-yonder/sqlalchemy\_exasol/compare/2.0.7...2.0.8](https://github.com/blue-yonder/sqlalchemy_exasol/compare/2.0.7...2.0.8)

Any idea on where I could look to find the root cause of the build failing?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 7, 2019, 6:32pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/2 "2019-10-07T18:32:13Z")

</div>

> [@BY-jk](#):
>
> As the tokens are too long to be encrypted using travis-cli

```auto
> travis encrypt --repo native-api/test_travis TOKEN=pypi-AgEIcHlwaS5vcmcCJGE4OTI5OGM4LWY5MWEtNGI5ZS05M2Q4LTBkMzkwZmEyMTIyNgACJXsicGVybWlzc2lvbnMiOiAidXNlciIsICJ2ZXJzaW9uIjogMX0AAAYg9li4PCqk6OT8WZhUr_mLrf6ZLMmR5qpQ3dFxleaCE50
Please add the following to your .travis.yml file:

  secure: "kEq9bDSr5TI8wbTM4tzvrWF2vsH2CcCb0fUnQlgHqgiFgNIJgL0sHLz3xAJRAsZE803AQhGkMvdQQ86vb9vQ5cdO1CC2X9fWqjQCd7WHGVokrj6qbt82gcd7heharKlQFRN+ScpJMyVQFtzQfZ5mkcwZGTgel9tRJdbsg1uaJENDbqbOE3fhTAoMIud5LK5IbtkqO7+U9EQZj2SesBSYxCAAsPP0L09tqSLCfjt8/fCklG0Za2AZekIOQJHu+OgAIhMeQN7Z1bLa+mmpjQD3xRxAwOmB58g0kpqFinlaAvv9IdEVKJBTBGyacr/KMiQAmgn8zBD6oYt+SSex/SDygfIsR7zSv3sQk3aAS9BqqOCMT7qMGmQEBDIyN2P+auoE08MkoZ8iHywGDXeysRVxq5KwjSQwPTkNAMxKJN1ij8OyslJPrUC84dab7eRQQZMKx/ZkNnvwS8RG6sXs3aJhxYzb/mzZsuiBdI1z6WDCNzq1ufhjXNrqQ4sVdql6Z07aN3dmav6W6j/97gcen9aM5ipZVFWCHWMvx9/2c+az2pDQIH0R6gCwTsTM4VbG6CocUP3wXf8JiyKF8ISE5KcfNVOMEzrvex2ItowFMxCH5E9ctNpvHcwArg5JBZaY8cjXkWSJ6n1YzL+CO8RgA0XkTdodB1oL9CvZ73x7VxKk="
```

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 7, 2019, 6:35pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/3 "2019-10-07T18:35:22Z")

</div>

Comparing [https://travis-ci.org/blue-yonder/sqlalchemy\_exasol/jobs/591866904#L315-L318](https://travis-ci.org/blue-yonder/sqlalchemy_exasol/jobs/591866904#L315-L318) and [https://travis-ci.org/blue-yonder/sqlalchemy\_exasol/jobs/592508182#L315-L317](https://travis-ci.org/blue-yonder/sqlalchemy_exasol/jobs/592508182#L315-L317), `PYPI_PASSWORD` is no longer set in your repository settings.

---

<div class="post-metadata">

**Author:** ![BY-jk](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@BY-jk](https://travis-ci.community/u/BY-jk)\
**Post date:** [October 7, 2019, 7:57pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/4 "2019-10-07T19:57:48Z")

</div>

Good catch! Now I wonder why that is, as the variable is set in the project settings. I have restricted the variable to the master branch. I will try out a new key that is not restricted to master and see if that makes this variable show up again.

---

<div class="post-metadata">

**Author:** ![BY-jk](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@BY-jk](https://travis-ci.community/u/BY-jk)\
**Post date:** [October 7, 2019, 8:01pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/5 "2019-10-07T20:01:33Z")

</div>

What is your Travis CLI version. On running that command I get the output  
`data too large - consider using travis encrypt-file or travis env set`

My travis cli version is 1.8.10

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [October 7, 2019, 8:13pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/6 "2019-10-07T20:13:53Z")

</div>

> [@BY-jk](#):
>
> I have restricted the variable to the master branch.

That’s the reason. Tag builds are not considered to be on the `master` branch (a tag is effectively a branch that you cannot add further commits to).

> [@BY-jk](#):
>
> My travis cli version is 1.8.10

Same, installed with `gem install travis` into a clean `ruby 2.4.7p357 (2019-08-28 revision 67796) [x64-mingw32]`; the command is run from a `Start Command Prompt with Ruby` prompt. Maybe you are formatting the command wrong or something.

---

<div class="post-metadata">

**Author:** ![BY-jk](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@BY-jk](https://travis-ci.community/u/BY-jk)\
**Post date:** [October 7, 2019, 8:22pm UTC](https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/7 "2019-10-07T20:22:33Z")

</div>

[https://travis-ci.org/blue-yonder/sqlalchemy\_exasol/jobs/592508182](https://travis-ci.org/blue-yonder/sqlalchemy_exasol/jobs/592508182) is green again and upload works.  
As @native-api pointed out, tag builds are not considered `master` which makes sense.  
Thank you for the quick support!
