This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unable to use socket send and sendall due to type error
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dhruve, eric.smith
Priority: normal Keywords:

Created on 2016-05-22 20:08 by Dhruve, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg266102 - (view) Author: Nick McElwaine (Dhruve) Date: 2016-05-22 20:08
import socket               # Import socket module
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)  
s.connect(hostname,port) # this works
message = 'text'
s.sendall(message) TypeError: a bytes-like object is required, not 'str'

    s.sendall(message)
TypeError: a bytes-like object is required, not 'str'
msg266103 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2016-05-22 20:12
You'll need to convert the string to bytes first, by using .encode().
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71274
2016-05-22 20:12:58eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg266103

resolution: not a bug
stage: resolved
2016-05-22 20:08:53Dhruvecreate