Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49783
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'causing': 0.04; 'socket': 0.07; 'bytes,': 0.09; 'encode': 0.09; 'wrong,': 0.09; 'python': 0.11; 'addr': 0.16; 'addr)': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'port))': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:sending': 0.16; 'typeerror:': 0.16; 'using,': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'server,': 0.19; 'examples': 0.20; '>>>': 0.22; 'handles': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'bytes': 0.24; 'module,': 0.24; 'subject:problem': 0.24; 'unicode': 0.24; 'appreciated': 0.26; 'tutorials': 0.26; 'header:In-Reply-To:1': 0.27; 'host': 0.29; 'along': 0.30; 'lines': 0.31; 'fine,': 0.31; 'anyone': 0.31; 'file': 0.32; 'interface': 0.32; '(most': 0.33; 'except': 0.35; 'something': 0.35; 'received:84': 0.35; 'test': 0.35; 'but': 0.35; 'version': 0.36; 'skip:" 50': 0.36; 'subject:data': 0.36; 'doing': 0.36; "didn't": 0.36; 'project': 0.37; 'server': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'how': 0.40; 'even': 0.60; 'simple': 0.61; "you're": 0.61; 'show': 0.63; 'school': 0.64; 'between': 0.67; 'header:Reply-To:1': 0.67; 'difficulty': 0.68; 'of:': 0.68; 'reply-to:no real name:2**0': 0.71; 'reply-to:addr:python.org': 0.84; 'sending,': 0.84; 'email addr:aol.com': 0.96 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=RZapVTdv c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=K2DDQYBT4xIA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=8WG8yZvtm9AA:10 a=3oc9M9_CAAAA:8 a=cXxU804Z2pPCnetSsVcA:9 a=wPNLvfGTeEIA:10 a=U8Ie8EnqySEA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Thu, 04 Jul 2013 00:02:21 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: socket data sending problem |
| References | <dff7d1f8-183d-42c3-b921-73875e431ccd@googlegroups.com> |
| In-Reply-To | <dff7d1f8-183d-42c3-b921-73875e431ccd@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4188.1372892534.3114.python-list@python.org> (permalink) |
| Lines | 45 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1372892534 news.xs4all.nl 15899 [2001:888:2000:d::a6]:37789 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:49783 |
Show key headers only | View raw
On 03/07/2013 23:38, ollietempleman@aol.com wrote:
> im trying to do a simple socket test program for a school project using the socket module, but im having difficulty in sending data between the client and host program.
>
> so far all tutorials and examples have used something along the lines of:
>
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> host = socket.gethostname()
> port = 12345
> s.connect((host, port))
>
>
> and received it on the server end with:
>
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> host = ''
> port = 12345
> s.bind((host, port))
> s.listen(1)
> conn, addr = s.accept()
> print ('client is at', addr)
> data = conn.recv(5)
> print(data)
>
> it all works fine, except for when i try to use:
>
> s.send("hello")
>
> to send data between the client and server, i just get this error message:
>
> >>>
> Traceback (most recent call last):
> File "C:/Users/Ollie/Documents/code/chatroom/client3.py", line 9, in <module>
> s.send("hello")
> TypeError: 'str' does not support the buffer interface
> >>>
>
> if anyone can either show me what im doing wrong, what this means and what's causing it, or even better how to fix it it would be greatly appreciated
>
You didn't say which version of Python you're using, but I think that
you're using Python 3.
A socket handles bytes, not Unicode strings, so you need to encode the
Unicode strings to bytes before sending, and decode the bytes to
Unicode strings after receiving.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
socket data sending problem ollietempleman@aol.com - 2013-07-03 15:38 -0700 Re: socket data sending problem Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-07-04 00:57 +0200 Re: socket data sending problem MRAB <python@mrabarnett.plus.com> - 2013-07-04 00:02 +0100
csiph-web