Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83500

Re: OSError: [WinError 10022] An invalid argument was supplied in udp python file

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:: [': 0.04; 'argument': 0.05; 'elif': 0.05; 'socket': 0.07; 'subject:file': 0.07; 'sys': 0.07; 'bytes.': 0.09; 'encode': 0.09; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'address)': 0.16; 'port))': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'supplied': 0.16; 'true:': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'passing': 0.19; 'subject:] ': 0.20; 'command': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; '15,': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'file': 0.32; 'run': 0.32; '(most': 0.33; 'skip:# 10': 0.33; 'test': 0.35; 'data,': 0.36; 'error.': 0.37; 'server': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'according': 0.40; 'removing': 0.60; 'hope': 0.61; "you're": 0.61; "you'll": 0.62; 'address': 0.63; 'header :Reply-To:1': 0.67; 'invalid': 0.68; 'reply-to:no real name:2**0': 0.71; 'listening': 0.74; 'address,': 0.75; 'reply- to:addr:gmail.com': 0.80; '1060': 0.84; 'failure:': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Kev Dwyer <kevin.p.dwyer@gmail.com>
Subject Re: OSError: [WinError 10022] An invalid argument was supplied in udp python file
Date Sat, 10 Jan 2015 11:43:35 +0000
References <CA+YdQ_54x4w_GUWw6_YLwX9Mb_CgoR8VQ0E1N3oE=r-QVaiv0A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host cpc5-hari13-2-0-cust222.20-2.cable.virginm.net
Mail-Copies-To kevin.p.dwyer@gmail.com
User-Agent KNode/4.14.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To kevin.p.dwyer@gmail.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17563.1420890228.18130.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1420890228 news.xs4all.nl 2839 [2001:888:2000:d::a6]:45792
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83500

Show key headers only | View raw


contro opinion wrote:

> When i test an udp.py file on server and client in python34.
> 
> 
>     #!/usr/bin/env python
>     import socket, sys
>     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>     MAX = 65535
>     PORT = 1060
>     if sys.argv[1:] == ['server']:
>         s.bind(('127.0.0.1', PORT))
>         print('Listening at', s.getsockname())
>         while True:
>               data, address = s.recvfrom(MAX)
>               print('The client at', address, 'says', repr(data))
>               s.sendto('Your data was %d bytes' % len(data), address)
>     elif sys.argv[1:] == ['client']:
>         print('Address before sending:',s.getsockname())
>         s.sendto('This is my message',('127.0.0.1', PORT))
>         print('Address after sending',s.getsockname())
>         data, address = s.recvfrom(MAX)
>         print('The server', address, 'says', repr(data))
>     else:
>       print('usage: udp_local.py server|client')
> 
> 
> The command `python udp.py server`  get output:
> Listening at ('127.0.0.1', 1060)
> 
> Why   `python udp.py client`  run failure:
> 
> Traceback (most recent call last):
>   File "d://udp.py", line 15, in <module>
>     print('Address before sending:', s.getsockname())
> OSError: [WinError 10022] An invalid argument was supplied


Hello,

According to http://stackoverflow.com/questions/15638214/socket-error-invalid-argument-supplied, the client socket doesn't have an address at time
when you call s.getsocketname.  This raises an exception on Windows.

Removing the 'Address before sending' line will prevent the error.

As you're using Python3, you'll find that passing strings to s.sendto raises
a TypeError; you'll need to encode the strings as bytes.

Hope that helps,

Kev

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: OSError: [WinError 10022] An invalid argument was supplied in udp python file Kev Dwyer <kevin.p.dwyer@gmail.com> - 2015-01-10 11:43 +0000

csiph-web