Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create message endpoint fails with Cloudflare 520 #7408

Open
pam-param-pam opened this issue Feb 26, 2025 · 0 comments
Open

Create message endpoint fails with Cloudflare 520 #7408

pam-param-pam opened this issue Feb 26, 2025 · 0 comments
Labels
bug synced Synced to internal tracker

Comments

@pam-param-pam
Copy link

Description

Create message endpoint fails with cloudflare's status code 520 when:

  • only files are supplied
  • the bigger the file size the more often it will fail
  • auth token provided is invalid

Steps to Reproduce

import httpx

size_mb = 7
size = size_mb * 1024 * 1024  # Convert MB to bytes

data = b'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
with open("random_file.txt", 'wb+') as file:
    while size > 0:
        chunk_size = min(1024 * 1024, size)
        file.write(data * (chunk_size // len(data)))
        size -= chunk_size

    channel_id = 1207210135194181685
    test_url = f"https://discord.com/api/v10/channels/{channel_id}/messages"
    with httpx.Client(timeout=None) as client:
        res = client.post(test_url, files={'file': file}, headers={"Authorization": "Bot invalidTokenHere"})
        print(res.status_code)

Weirdly, this only happens when using the httpx library—when I switch to requests, I get a 401 as expected.

This suggests that httpx and requests handle the request differently, but it also indicates a potential bug in the API

Expected Behavior

The API returns 401 status code.

Current Behavior

The API returns 520 status code.

Screenshots/Videos

No response

Client and System Information

Windows 10
python=3.9
httpx==0.26.0

@lsdimagine lsdimagine added the synced Synced to internal tracker label Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug synced Synced to internal tracker
Projects
None yet
Development

No branches or pull requests

2 participants