R
Railway12mo ago
qxh

(Python) Can't send HTTP requests properly within railway

I'm unable to properly send out HTTP requests using the aiohttp module. It works completely fine on my local PC, but is not working on railway. For some reason when I send my request through railway, it adds a "%27" at the end of the param what It's the exact same code and I'm pushing it through GH to stay in sync. I've also ensured that all requirements were installed to the latest version, and double checking using the --force flag. Python version was set to 3.11 aswell. This makes 0 sense The code itself:
async with request("GET", "https://nekobot.xyz/api/image", params={"type": "4k"}) as response:
json: dict[str, bool | int | str] = await response.json()

await interaction.response.send_message(
embed=predef_embeds.Default(
self.basecog.client,
None,
props={
"image": json.get(
"message",
API_NADA_RETURN,
)
},
),
ephemeral=ephemeral,
)
async with request("GET", "https://nekobot.xyz/api/image", params={"type": "4k"}) as response:
json: dict[str, bool | int | str] = await response.json()

await interaction.response.send_message(
embed=predef_embeds.Default(
self.basecog.client,
None,
props={
"image": json.get(
"message",
API_NADA_RETURN,
)
},
),
ephemeral=ephemeral,
)
Solution:
Seems like Cloudflare is blocking the request
Jump to solution
11 Replies
Percy
Percy12mo ago
Project ID: bc2620b0-2975-478d-8dbb-5f726c4e3748
jonbeau
jonbeau12mo ago
%27 is ', and the closing ' is missing in URL(), hm
fad
fad12mo ago
To me, it just looks like Discord incorrectly parsed the closing ' as part of the URL and performed URL encoding on it. I think the issue lies elsewhere. Error message seems to suggest that the response is an HTML response instead of JSON one, and yet when I try to visit https://nekobot.xyz/api/image?type=4k%27 I get a JSON response instead of HTML.
qxh
qxh12mo ago
But aiohttp is performing the request, not Discord, I'm just sending the resulting image url inside the message key as the embed image url, but it's not even passing through the .json() parsing part
fad
fad12mo ago
No, no. I mean when Discord is displaying that message, it's parsing the URL before it's displaying it. During that process, it incorrectly assumes the ' is part of the URL.
qxh
qxh12mo ago
But then why does it work perfectly fine on my pc
fad
fad12mo ago
Could you perhaps display the raw body response? Maybe it'll tell you the reason why
qxh
qxh12mo ago
Sure lemme deploy rq
qxh
qxh12mo ago
It seems like the API endpoint is blocking railway yeet
Solution
fad
fad12mo ago
Seems like Cloudflare is blocking the request
qxh
qxh12mo ago
Well that's about it then ig, thx for the help annoyed