bluesky-social / atproto

Social networking technology created by Bluesky
Other
7.21k stars 511 forks source link

Error sending post: Too little data for declared Content-Length #3088

Open maglore9900 opened 2 days ago

maglore9900 commented 2 days ago

Describe the bug

Using the following code, which is almost exactly the same as the example, when I attempt to post with an image I always receive the error "Error sending post: Too little data for declared Content-Length"

I have tried different images, and a few different permutations of the code. I can successfully post without images.

Example:

with open('my_cat.jpg', 'rb') as f:
    img_data = f.read()

client.send_image(text='I love my cat', image=img_data, image_alt='My cat mittens')

My code: main.py

from modules import blue, masto
import environ

env = environ.Env()
environ.Env.read_env()

b = blue.Blue(env)
m = masto.Mastodon_Status(env)

with open("tea2.jpg", 'rb') as f:
    f.read()        
    b.post("Ponder the tea eternal", f, "man confused by tea")

# b.post("yet another test, sorry for the spam")

blue.py

from atproto import Client

class Blue():
    def __init__(self, env):
        self.env = env
        self.client = Client()
        self.client.login(self.env('bsky_handle'), self.env('bsky_pass'))

    def post(self, message, file=None, image_desc=None):
        try: 
            if file:
                post = self.client.send_image(text=message, image=file, image_alt=image_desc)
            else:
                post = self.client.send_post('Hello world! This is a test.')
        except Exception as e:
            print("Error sending post:", str(e))

To Reproduce

  1. Attempt to send a post with an image using the example provided in the docs

Expected behavior

I would expect the doc example to work

Details