Python does not work

2021-07-13 Thread rubiks solver
   When I run python 3.9.6 on visual studio code it opens multiple python
   setup windows.

   I rebooted my computer. Same result.







   Is this a bug?
-- 
https://mail.python.org/mailman/listinfo/python-list


Simple SSL client hangs

2021-07-13 Thread Loris Bennett
Hi,

In Perl I have the following

  use IO::Socket::SSL;

  my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
  PeerPort => 12345,
 );

  my $line = <$my_socket>;
  print("$line\n");
  say $my_socket 'ECHO 1';
  $line = <$my_socket>;
  print("$line\n");

This runs as expected and I get

  200 Some Server Somewhere - Hello [123.456.789.123]

  310 Hello Echo

If I try the same with the following Python code:

  import socket
  import ssl

  HOST = "some.server.somewhere"
  PORT = 12345

  context = ssl.create_default_context()

  with socket.create_connection((HOST, PORT)) as sock:
  with context.wrap_socket(sock, server_hostname=HOST) as ssock:
  data = ssock.recv(1024)
  print(data.decode())
  ssock.write(b'ECHO 1')
  data = ssock.read(1024)
  print(data.decode())

I get a timeout for the 'ECHO' command:

  200 Some Server Somewhere - Hello [123.456.789.123]

  501 Timeout

Does anyone have an idea what I might be doing wrong?

Cheers,

Loris

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple SSL client hangs

2021-07-13 Thread Douglas Wells
In article <[email protected]>,
Loris Bennett  wrote:
>In Perl I have the following
>
>  use IO::Socket::SSL;
>  my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
> PeerPort => 12345,
>);
>  my $line = <$my_socket>;
>  print("$line\n");
>  say $my_socket 'ECHO 1';
>  $line = <$my_socket>;
>  print("$line\n");
>
>This runs as expected and I get
>
>  200 Some Server Somewhere - Hello [123.456.789.123]
>  310 Hello Echo
>
>If I try the same with the following Python code:
>
>  import socket
>  import ssl
>  HOST = "some.server.somewhere"
>  PORT = 12345
>  context = ssl.create_default_context()
>  with socket.create_connection((HOST, PORT)) as sock:
>  with context.wrap_socket(sock, server_hostname=HOST) as ssock:
>  data = ssock.recv(1024)
>  print(data.decode())
>  ssock.write(b'ECHO 1')
>  data = ssock.read(1024)
>  print(data.decode())
>
>I get a timeout for the 'ECHO' command:
>
>  200 Some Server Somewhere - Hello [123.456.789.123]
>  501 Timeout
>
>Does anyone have an idea what I might be doing wrong?

Loris,

You don't specify the type of your server, but it looks like a
"normal" SMTP or NNTP or whatever server.  This type of server is line
oriented.

The Perl "say" operation adds a trailing line terminator.  The Python
"ssl:write" does not.  Try adding an appropriate line terminator to
your Python code.  Most likely it needs to be CR-LF.  Perhaps use
"ssock.write(b'ECHO 1\r\n')

 - dmw
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple SSL client hangs

2021-07-13 Thread MRAB

On 2021-07-13 08:50, Loris Bennett wrote:

Hi,

In Perl I have the following

   use IO::Socket::SSL;

   my $my_socket = new IO::Socket::SSL(PeerAddr => 'some.server.somewhere,
  PeerPort => 12345,
 );

   my $line = <$my_socket>;
   print("$line\n");
   say $my_socket 'ECHO 1';
   $line = <$my_socket>;
   print("$line\n");

This runs as expected and I get

   200 Some Server Somewhere - Hello [123.456.789.123]

   310 Hello Echo

If I try the same with the following Python code:

   import socket
   import ssl

   HOST = "some.server.somewhere"
   PORT = 12345

   context = ssl.create_default_context()

   with socket.create_connection((HOST, PORT)) as sock:
   with context.wrap_socket(sock, server_hostname=HOST) as ssock:
   data = ssock.recv(1024)
   print(data.decode())
   ssock.write(b'ECHO 1')
   data = ssock.read(1024)
   print(data.decode())

I get a timeout for the 'ECHO' command:

   200 Some Server Somewhere - Hello [123.456.789.123]

   501 Timeout

Does anyone have an idea what I might be doing wrong?


The docs for Perl says that 'say' appends a newline.

On the other hand, 'ssock.write' doesn't append a newline.

Could that be the problem?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python does not work

2021-07-13 Thread Mats Wichmann

On 7/13/21 3:05 AM, rubiks solver wrote:

When I run python 3.9.6 on visual studio code it opens multiple python
setup windows.

I rebooted my computer. Same result.


Is this a bug?


No, it's a setup problem.

Sounds like when you pointed Code at Python, you pointed it at the 
installer. You should be able to adjust it to point to the real Python 
executable.


Unfortunately, since there are so many choices how things could have 
been installed from the various different sources, but a guess at the 
path you want would be something like:


...\AppData\Local\Programs\Python\Python39\python.exe


--
https://mail.python.org/mailman/listinfo/python-list


Re: argparse support of/by argparse

2021-07-13 Thread lucas

Mmmh, that may work just fine !
Thanks for that idea, ChrisA, i'm looking forward to implement that.

Best wishes,
--lucas



On 12/07/2021 21:33, Chris Angelico wrote:

On Tue, Jul 13, 2021 at 5:22 AM lucas  wrote:


Hello everyone,

Let us consider this patch of code:

  import argparse

  def parse_cli() -> argparse.Namespace:
  parser = argparse.ArgumentParser()
  parser.add_argument('n', type=int)
  return parser.parse_args()

  args = parse_cli()
  print(args.n + ' ')  # type error

Running CPython on it will raise a TypeError, and running Mypy on it
will indicate that no issues were found.

I was wondering if there is any way for me to have mypy detecting the
args.n type, based on the type keyword of the parser.add_argument function ?

It appears that some type annotations were added to tierce party
modules, provided by mypy itself. Is there a technical issue preventing
such work to be made for argparse (or other CLI ; i didn't find anything
for others either)



Seems complicated, since it depends on a lot of run-time information.
What if you flip the problem on its head? Instead of creating the
argparser and letting that govern the types, maybe create a dataclass,
and then programmatically build the parser.

from dataclasses import dataclass
import argparse

@dataclass
class Args:
 n: int

def parse_cli() -> Args:
 parser = argparse.ArgumentParser()
 for field, typ in Args.__dataclass_fields__.items():
 if hasattr(typ, "type"): typ = typ.type # Python 3.10 changed
things a bit
 parser.add_argument(field, type=typ)
 return Args(**vars(parser.parse_args()))

args = parse_cli()
print(args.n + ' ')


Only barely tested it and didn't try MyPy, but that's the basic idea.
You'd have to figure out the tidiest way to define all the other
attributes of your arguments (help text, etc), but ideally, all the
info should be able to be coded in the dataclass.

Incidentally, you could choose to make parse_cli into a classmethod of
Args. Might be cleaner.

ChrisA


--
https://mail.python.org/mailman/listinfo/python-list


Tkinter widgets for desktop database application

2021-07-13 Thread Rich Shepard

I'm writing a couple of database applications that use tkinter, and not a
web browser, for the UI and I'm still trying to determine the optimal way to
do this.

Individual tk and ttk widgets (LineEntry, Combobox, etc.) work for adding
and modifying individual database table rows but not for displaying multiple
rows returned by a SELECT statement. To view all rows returned by the SQL
statement would a pythonReport be used?

I'm working on learning to use tksheet as the sole widget because it can
display multiple rows from a database table as well as add new rows and
modify existing ones (one or more columns in each row).

What have other developers used for the UI on a stand-alone database
application not using a web browser? I've struggled with finding the most
efficient and optimal non-brower UI for months and would like to have a
solid path toward a working solution. I know too little to make this
decision and want advice, suggestions, and recommendations from experienced
developers.

TIA,

Rich

--
https://mail.python.org/mailman/listinfo/python-list