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

[refactor/tls] TypeError when sending file attachment #763

Open
4 tasks done
hotapmfhypo opened this issue Nov 17, 2024 · 4 comments
Open
4 tasks done

[refactor/tls] TypeError when sending file attachment #763

hotapmfhypo opened this issue Nov 17, 2024 · 4 comments
Labels
unconfirmed bug Unconfirmed bug

Comments

@hotapmfhypo
Copy link

hotapmfhypo commented Nov 17, 2024

Summary

when trying to DM a user with the send() method I get a type error

Reproduction Steps

-using refactor/tls branch
-try to DM .jpg to user with their user ID

Code

import discord

client = discord.Client()

@client.event
async def on_ready():
    user = await client.fetch_user(userID) #user ID as an int
    with open('cat.jpg', 'rb') as f:
        await user.send(file=discord.File(f))

client.run('token') #my token

Expected Results

send jpg to user

Actual Results

t.py", line 592, in _run_event
t.py", line 592, in _run_event
await coro(*args, **kwargs)
File "c:\Users\Desktop\discord pybot\main.py", line 9, in on_ready
await coro(*args, **kwargs)
File "c:\Users\Desktop\discord pybot\main.py", line 9, in on_ready
File "c:\Users\Desktop\discord pybot\main.py", line 9, in on_ready
await user.send(
File "C:\Users\Desktop\venvs\venv3.12\Lib\site-packages\discord\abc.py", line 1883, in send
data = await state.http.send_message(channel.id, params=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\venvs\venv3.12\Lib\site-packages\discord\http.py", line 808, in request
response = await self.__session.request(method, url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\venvs\venv3.12\Lib\site-packages\curl_cffi\requests\session.py", line 899, in request
req, buffer, header_buffer, q, header_recved, quit_now = self._set_curl_options(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\venvs\venv3.12\Lib\site-packages\curl_cffi\requests\session.py", line 238, in _set_curl_options
raise TypeError("data must be dict, str, BytesIO or bytes")
TypeError: data must be dict, str, BytesIO or bytes

System Information

  • Python v3.12.2-final
  • discord.py-self v2.1.0-alpha
    • discord.py-self metadata: v2.1.0a4855+g72c6a593
  • curl_cffi v0.6.0b7
  • aiohttp v3.11.2
  • system info: Windows 10 10.0.19045

Checklist

  • I have confirmed I am using unmodified discord.py-self and not the upstream discord.py.
  • I have searched the open issues for duplicates.
  • I have shared the entire traceback.
  • I am using a user token (and it isn't visible in the code).

Additional Information

I'm not sure if this error has to do with this module or if its just a problem with how I'm implementing the code in general so sorry in advance if its the latter. I saw someone mention issues with curl_cffi after using the refactor/tls branch so I wanted to ask.

@hotapmfhypo hotapmfhypo added the unconfirmed bug Unconfirmed bug label Nov 17, 2024
@hotapmfhypo
Copy link
Author

I want to add that when using get_user() for the user object rather than fetch_user() then the attachment works.

@dolfies
Copy link
Owner

dolfies commented Dec 1, 2024

The refactor/tls branch is alpha and very unfinished. Regardless, thanks for the bug report because I didn't know about this and it needs to be fixed before the branch is merged into master.

@dolfies dolfies changed the title TypeError when sending file attachment [refactor/tls] TypeError when sending file attachment Dec 1, 2024
@dolfies
Copy link
Owner

dolfies commented Dec 2, 2024

Hey @hotapmfhypo, does this still occur using the latest version of the refactor/tls branch with the latest version of curl_cffi?

@hippo2point0
Copy link

hippo2point0 commented Dec 17, 2024

hey @dolfies this is OP. sorry I got locked out of my other account. im still getting the same error even using the new branch when trying to send files.

File "c:\Users\user\Desktop\venvs\venv3.12\Lib\site-packages\discord\client.py", line 596, in _run_event
await coro(*args, **kwargs)
File "c:\Users\user\Desktop\discord pybot\discordbot.py", line 40, in on_ready
await c.send(file=discord.File('cat.jpg'))
File "c:\Users\user\Desktop\venvs\venv3.12\Lib\site-packages\discord\abc.py", line 1883, in send
data = await state.http.send_message(channel.id, params=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\user\Desktop\venvs\venv3.12\Lib\site-packages\discord\http.py", line 817, in request
response = await self.__session.request(method, url, **kwargs, stream=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\user\Desktop\venvs\venv3.12\Lib\site-packages\curl_cffi\requests\session.py", line 899, in request
req, buffer, header_buffer, q, header_recved, quit_now = self._set_curl_options(
^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\user\Desktop\venvs\venv3.12\Lib\site-packages\curl_cffi\requests\session.py", line 238, in _set_curl_options
raise TypeError("data must be dict, str, BytesIO or bytes")
TypeError: data must be dict, str, BytesIO or bytes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug Unconfirmed bug
Projects
None yet
Development

No branches or pull requests

3 participants