@@ -530,7 +530,7 @@ def __init__(self, host=None, user=None, password="",
530
530
charset = '' , sql_mode = None ,
531
531
read_default_file = None , conv = None , use_unicode = None ,
532
532
client_flag = 0 , cursorclass = Cursor , init_command = None ,
533
- connect_timeout = None , ssl = None , read_default_group = None ,
533
+ connect_timeout = 10 , ssl = None , read_default_group = None ,
534
534
compress = None , named_pipe = None , no_delay = None ,
535
535
autocommit = False , db = None , passwd = None , local_infile = False ,
536
536
max_allowed_packet = 16 * 1024 * 1024 , defer_connect = False ,
@@ -564,6 +564,7 @@ def __init__(self, host=None, user=None, password="",
564
564
cursorclass: Custom cursor class to use.
565
565
init_command: Initial SQL statement to run when connection is established.
566
566
connect_timeout: Timeout before throwing an exception when connecting.
567
+ (default: 10, min: 1, max: 31536000)
567
568
ssl:
568
569
A dict of arguments similar to mysql_ssl_set()'s parameters.
569
570
For now the capath and cipher arguments are not supported.
@@ -646,6 +647,9 @@ def _config(key, arg):
646
647
self .db = database
647
648
self .unix_socket = unix_socket
648
649
self .bind_address = bind_address
650
+ if not (0 < connect_timeout <= 31536000 ):
651
+ raise ValueError ("connect_timeout should be >0 and <=31536000" )
652
+ self .connect_timeout = connect_timeout or None
649
653
if read_timeout is not None and read_timeout <= 0 :
650
654
raise ValueError ("read_timeout should be >= 0" )
651
655
self ._read_timeout = read_timeout
@@ -670,7 +674,6 @@ def _config(key, arg):
670
674
self .client_flag = client_flag
671
675
672
676
self .cursorclass = cursorclass
673
- self .connect_timeout = connect_timeout or None
674
677
675
678
self ._result = None
676
679
self ._affected_rows = 0
0 commit comments