PlatformIO Community

ESP32 Bintray OTA 401 Client Error after setup

Error on upload:
Failed to submit package: 401 Client Error: Unauthorized for URL

The template I downloaded:
JFrog Bintray

  1. Added SSID, password, Bintray API token to the system environment (/etc/profile), and it is showing up as a variable.
  2. Edited the platformio.ini file with my project’s properties.
  3. Changed to release and uploaded, and all this resulted in the error mentioned above.

Observation
Upon following the link, which was in the error output, there was a plain text saying {"message":"Package '' was not found"}. I tried changing the publish_firmware.py file by commenting out the "content" at the end of line 48. On that link, I got a login prompt, where I put in my password and username, but it doesn’t allow me in.

OS: macOS 10.15.7
PlatformIO IDE: VSCode

I see there’s an open pull request for a better instruction manual from this repo: https://github.com/r0oland/bintray-secure-ota

Maybe you can recheck your steps there and see the error? "message":"Package '' was not found"} sounds to me like some package name or URL wasn’t properly configured.

1 Like

You can find my Bintray repo/package here.

I have done the setup in the way the documentation told me to, the issue sticks.

Are you also using the same code as from the config?

Can you, in this line,

add the statements

    print("bintray config: %s" % str(bintray_config))

to double check what user, repistory and package it’s using?

1 Like

My output:
bintray config: {'user': 'valordev', 'repository': 'esp32-chart', 'package': 'data-chart-esp32', 'api_token': '${sysenv.BINTRAY_API_TOKEN}'}

Also, tried Ivan’s and Roland’s repo of Bintray Secure OTA, but neither of them work for me.

I thought your package was called esp32-data-chart though in your JFrog bintray account?

1 Like

Good find, I was using it because originally I recreated the repo/package. Also the GitHub uses that name.

However, bad news… Same issue.

Okay, weird. I’ll setup my own account and follow the instructions step-by-step and see if I encounter the same error.

I don’t know whether that’s supposed to be there or if it wasn’t able to substitute the environment vairable properly. But if the token wasn’t right I guess you would be getting an “Unauthorized” error, not a “does not existt” error? Still, try and replace this in the platformio.ini with a constant value.

1 Like

I changed it manually to my token, and it pushed the update to my Bintray. Even though this might not be the fix for everyone, it is definitely for me. Thank you so much.

If you could figure out why it doesn’t read my system environment there, that would be the true solution. I just want to let you know, I put the SSID and the password in my system environment, and that is being read.

According to the documentation that should work. How and in which shell have you exported the environment variable? Maybe it just isn’t visible when PlatformIO is run in a new shell? THat’s very OS-dependent…

Well, I put it in /etc/profile as a system variable. When I printed it, it just said: ${sysenv.BINTRAY_API_TOKEN} like it doesn’t read it.

Could this be a Python issue?
I mean, the SSID and password is being read, why not this one? macOS uses Python 2.7, you know?

PlatformIO is Python 3.x program and current Python 2.7 support is deprecated and will be removed. If you are using PlatformIO from within VSCode and the upload button there, it will internally use its own Python 3.7 installation. You can start a PIO terminal and execute pio system info to see for youself.

But you’re absolutely right, if it worked for all other 3 environment variables (SSID, PW, bintray token) there and it only works for 3, I don’t know why… Maybe when the firmware is compiled it is done so under the full system environment and when it executes the upload SCons script, it started in a minimalistic environment where these things are not read out? The other possibility would be a typo in the environment.

You can check what’s going on there by adding more debug statements to the python publish firmware script, see here. Things like

print("Full build environment")
print(env)
print("OS environment variables")
print(os.environ)

etc.

I can find the BINTRAY_API_TOKEN in the print(os.environ) output, but the print(env) output is <SCons.Script.SConscript.SConsEnvironment object at 0x101f26e20> which is kinda weird.

Like why doesn’t the firmware want to read my system environment variable? The best option here for me is to just make a .gitignore for my platformio.ini and just use the token manually. Not exactly the comfiest setup, I’d say.

Sorry you need print(env.Dump()) there.

Maybe not the best fix, but I have something.
In publish_firmware.py do the following changes:

  1. Add from os import environ on the top of your file.
  2. Change the auth line from bintray_config['api_token'] to environ['BINTRAY_API_TOKEN'] (or whatever your token variable is)

Ah, thank you. Well, there is a BINTRAY_API_TOKEN in the dump, but I just went with my solution. Maybe, I’ll make my own OTA fork with this change later. :rofl: