Getting Empty Output from Bash Script
I have a painfully simple Bash script that retrieves data from a publicly (anonymously) accessible REST API. Sometimes the script outputs the expected JSON, but the vast majority of the time, I'm not getting the JSON output from the
curl
command.
What could possibly be happening?
If I run this in a Linux shell, it works every single time.54 Replies
The same command works perfectly fine in a Linux shell.
Let me investigate
I'm trying Python with
httpx
instead. Maybe it's more reliable that way.
Was hoping to use Bash script for simplicity thoughPython works perfectly, on the first try
bash relies on stdout for result while python works through file
Let me try using
httpie
from Bash scriptit's just a race condition on stdout
sleep 1
after curl
😆I can reproduce but this is really dumbfounding me
it's not just a race condition
I found another odd behavior.
It works in Linux shell, but "not found" in Windmill
name is empty in your example
Oops
oh you mean pip3 install
Still the same
But the Python example, with
httpx
works just fineit's really weird
It's not a problem finding the
http
binary .... because I can do http --version
and it prints the versionSee, it prints the version, but not the output from the API call
if one pipe with jq it works everytime
curl --silent https://api.nationalize.io?name=michael
echo ""
this will work everytime
Weird ...
it looks like the buffer is not getting drained
but I think that's a bash thing
Yup, confirmed. That fixes the issue with
curl
.
But with httpie I still just get "not found"
Maybe separate issuesdefinitely separate
Seems like a variable expansion issue in Bash. I hard-coded a value and
http
works.Sorry, that was coming from curl. Not HTTP. Hard-coding value still fails
does this command work on linux ?
Yup
i committed a fix that will avoid the need for echo ""
Do you want a new bug report for the "not found" issue?
I'm on it
will probably solve it soon
I cannot reproduce
Hmm...
Trying it another way, using a Docker container
note that i'm having the echo "" baked in as part of my new fix
Try this now ....
?
Calling API with PowerShell instead of
http
Worked fine, first try
lol
Maybe something odd with the
http
utility ... really odd though.
I'm not doing any HTTP proxyingNot found is really really weird
can you do -v or something ?
Yeah, that's what I thought. I could expect many other errors, but not taht
http --verbose "https://api.nationalize.io?name=Trevor"
That's .... bizarre? It's literally the same URL
They must be doing some server-side check on the User-Agent
header?
But it works in Linux shell .....user agent would be the same
Oh well, I have plenty of alternatives. I'll just use PowerShell or Python, or
curl
in Bash
Yeah, just thought of that after I posted it
Let me do --verbose from Linux shellOlder version of HTTPie
Whatever, I'm not worried about it. At least you verified it's not an issue on your side.
powershell is pretty fat: https://github.com/PowerShell/PowerShell-Docker#examples
GitHub
GitHub - PowerShell/PowerShell-Docker: Repository for building Powe...
Repository for building PowerShell Docker images. Contribute to PowerShell/PowerShell-Docker development by creating an account on GitHub.
220MB just for powershell...
Yup, but it saves tons of development time