realpython / realpython/materials

hi There, upon running the codes below, i have the problem in the last 2 lines : sock.sendto(message.format(i, time.asctime()), server_address) TypeError: a bytes-like object is required, not 'str'

Open
#227 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
5.2k
Forks
5.3k
Avg merge
4d 10h
Merged PRs (30d)
10

Description

Import Module

import socket
import time

Create a TCP/IP socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

Connect the socket to the port where the server is listening

server_address = ("localhost", 10000)

print('[+] Connecting to %s Port %s' % server_address)

message="Message No. {} | Sent By Client At Time {} "

for i in range(15):
sock.sendto(message.format(i, time.asctime()), server_address)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the UDP socket snippet shown in the issue and inspect the arguments passed to sock.sendto. Confirm that the example completes all 15 sends without the reported TypeError and that its documented behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.