= = = = = = = = = = = = = = = = = = = = = = = = = = = = =   t e s t   s e s s i o n   s t a r t s   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 p l a t f o r m   w i n 3 2   - -   P y t h o n   3 . 1 4 . 0 ,   p y t e s t - 9 . 0 . 3 ,   p l u g g y - 1 . 6 . 0 
 
 r o o t d i r :   C : \ U s e r s \ A r y a n   S h a r m a \ D e s k t o p \ s m o o t h - a p i \ p a c k a g e s \ s m o o t h - a p i - p y 
 
 c o n f i g f i l e :   p y p r o j e c t . t o m l 
 
 p l u g i n s :   a n y i o - 4 . 1 2 . 1 ,   a s y n c i o - 1 . 4 . 0 
 
 a s y n c i o :   m o d e = M o d e . S T R I C T ,   d e b u g = F a l s e ,   a s y n c i o _ d e f a u l t _ f i x t u r e _ l o o p _ s c o p e = N o n e ,   a s y n c i o _ d e f a u l t _ t e s t _ l o o p _ s c o p e = f u n c t i o n 
 
 c o l l e c t e d   2 3   i t e m s 
 
 
 
 t e s t s \ t e s t _ c o n c u r r e n c y . p y   E                                                                                             [     4 % ] 
 
 t e s t s \ t e s t _ d e d u p l i c a t i o n . p y   . . . . . . . 
 
 [ B e n c h m a r k ]   2 0 0   c o n c u r r e n t   r e q u e s t s   k%  5   r u n s   |   p l a i n   a v g :   1 . 2 6 m s   |   d e d u p e d   a v g :   1 . 5 6 m s 
 
 .                                                                           [   3 9 % ] 
 
 t e s t s \ t e s t _ e x c e p t i o n s . p y   . . .                                                                                           [   5 2 % ] 
 
 t e s t s \ t e s t _ i s o l a t i o n . p y   E                                                                                                 [   5 6 % ] 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y   E E E E E E E E E E                                                                             [ 1 0 0 % ] 
 
 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =   E R R O R S   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 _ _ _ _ _ _ _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ a s y n c _ w r a p p e r _ c o n c u r r e n c y   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 D 7 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 9 8 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 D 7 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 D 7 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 5 4 A 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 D 7 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 9 8 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 D 3 C 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 D 7 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
                 i m p o r t   r e q u e s t s 
 
 >               r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 
 
 t e s t s \ t e s t _ c o n c u r r e n c y . p y : 1 2 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 5 4 A 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 4 D 7 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ d e c o r a t o r _ i s o l a t i o n _ a n d _ r u n t i m e _ o v e r r i d e   _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 B 9 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 9 1 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 B 9 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 8 E F 9 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 9 1 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 0 A D 1 4 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 
 
 t e s t s \ t e s t _ i s o l a t i o n . p y : 1 0 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 8 E F 9 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ r e t r i e s _ o n _ 5 0 0 _ a n d _ e v e n t u a l l y _ s u c c e e d s   _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 D 1 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 A 9 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 D 1 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 2 6 0 F 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 A 9 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 3 2 7 C 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 2 6 0 F 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 C 1 D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ r e t r y _ r e s p e c t s _ r e t r y _ o n _ c o d e s   _ _ _ _ _ _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 6 4 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 3 E 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 6 4 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 6 4 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 1 1 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 6 4 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 3 E 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 2 5 E D 4 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 6 4 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 1 1 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 6 4 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ c i r c u i t _ t r i p s _ a n d _ r e t u r n s _ f a l l b a c k   _ _ _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 E 9 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 C 3 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 E 9 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 E 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 7 1 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 E 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 C 3 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 0 5 2 C C 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 E 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 7 1 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E E 4 E 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _   E R R O R   a t   s e t u p   o f   t e s t _ c i r c u i t _ o p e n _ r a i s e s _ r u n t i m e _ e r r o r _ w i t h o u t _ f a l l b a c k   _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 B 9 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 9 5 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 B 9 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 1 0 F 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 9 5 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 2 8 E F 4 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 1 0 F 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 2 0 B 9 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ c i r c u i t _ r e c o v e r s _ a f t e r _ c o o l d o w n   _ _ _ _ _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 E 0 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 8 B 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 E 0 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 E 0 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 3 A F 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 E 0 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 8 B 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 0 D E 4 0 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 E 0 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 8 3 A F 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 2 E 0 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ d e f a u l t _ b e h a v i o r   _ _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 B D 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 6 8 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 B D 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 B D 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 D 8 0 A D 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 B D 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 6 8 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 4 1 E 3 8 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 B D 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 D 8 0 A D 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 9 D 3 B D 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ f a l l b a c k _ a n d _ s t d e r r   _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C 5 A 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 1 6 1 5 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C 5 A 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C 5 A 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 0 3 D 1 8 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C 5 A 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 1 6 1 5 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 0 A 6 0 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C 5 A 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 0 3 D 1 8 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C 5 A 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ a s y n c _ f a l l b a c k _ a n d _ s t d e r r   _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C D 1 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 1 7 2 5 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C D 1 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 0 E 3 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 1 7 2 5 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 4 4 6 5 8 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 3 0 E 3 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 C D 1 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ c u s t o m _ f a l l b a c k   _ _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D 4 8 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E 7 5 A 9 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D 4 8 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D 4 8 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F C 7 D A 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D 4 8 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E 7 5 A 9 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 4 5 E 3 8 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D 4 8 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F C 7 D A 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D 4 8 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 _ _ _ _ _ _ _ _ _   E R R O R   a t   s e t u p   o f   t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ c u s t o m _ c a l l b a c k   _ _ _ _ _ _ _ _ _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D B F 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
 >                       s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 1 9 8 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 8 5 :   i n   c r e a t e _ c o n n e c t i o n 
 
         r a i s e   e r r 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 a d d r e s s   =   ( ' l o c a l h o s t ' ,   3 0 0 1 ) ,   t i m e o u t   =   N o n e ,   s o u r c e _ a d d r e s s   =   N o n e 
 
 s o c k e t _ o p t i o n s   =   [ ( 6 ,   1 ,   1 ) ] 
 
 
 
         d e f   c r e a t e _ c o n n e c t i o n ( 
 
                 a d d r e s s :   t u p l e [ s t r ,   i n t ] , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 s o u r c e _ a d d r e s s :   t u p l e [ s t r ,   i n t ]   |   N o n e   =   N o n e , 
 
                 s o c k e t _ o p t i o n s :   _ T Y P E _ S O C K E T _ O P T I O N S   |   N o n e   =   N o n e , 
 
         )   - >   s o c k e t . s o c k e t : 
 
                 " " " C o n n e c t   t o   * a d d r e s s *   a n d   r e t u r n   t h e   s o c k e t   o b j e c t . 
 
         
 
                 C o n v e n i e n c e   f u n c t i o n .     C o n n e c t   t o   * a d d r e s s *   ( a   2 - t u p l e   ` ` ( h o s t , 
 
                 p o r t ) ` ` )   a n d   r e t u r n   t h e   s o c k e t   o b j e c t .     P a s s i n g   t h e   o p t i o n a l 
 
                 * t i m e o u t *   p a r a m e t e r   w i l l   s e t   t h e   t i m e o u t   o n   t h e   s o c k e t   i n s t a n c e 
 
                 b e f o r e   a t t e m p t i n g   t o   c o n n e c t .     I f   n o   * t i m e o u t *   i s   s u p p l i e d ,   t h e 
 
                 g l o b a l   d e f a u l t   t i m e o u t   s e t t i n g   r e t u r n e d   b y   : f u n c : ` s o c k e t . g e t d e f a u l t t i m e o u t ` 
 
                 i s   u s e d .     I f   * s o u r c e _ a d d r e s s *   i s   s e t   i t   m u s t   b e   a   t u p l e   o f   ( h o s t ,   p o r t ) 
 
                 f o r   t h e   s o c k e t   t o   b i n d   a s   a   s o u r c e   a d d r e s s   b e f o r e   m a k i n g   t h e   c o n n e c t i o n . 
 
                 A n   h o s t   o f   ' '   o r   p o r t   0   t e l l s   t h e   O S   t o   u s e   t h e   d e f a u l t . 
 
                 " " " 
 
         
 
                 h o s t ,   p o r t   =   a d d r e s s 
 
                 i f   h o s t . s t a r t s w i t h ( " [ " ) : 
 
                         h o s t   =   h o s t . s t r i p ( " [ ] " ) 
 
                 e r r   =   N o n e 
 
         
 
                 #   U s i n g   t h e   v a l u e   f r o m   a l l o w e d _ g a i _ f a m i l y ( )   i n   t h e   c o n t e x t   o f   g e t a d d r i n f o   l e t s 
 
                 #   u s   s e l e c t   w h e t h e r   t o   w o r k   w i t h   I P v 4   D N S   r e c o r d s ,   I P v 6   r e c o r d s ,   o r   b o t h . 
 
                 #   T h e   o r i g i n a l   c r e a t e _ c o n n e c t i o n   f u n c t i o n   a l w a y s   r e t u r n s   a l l   r e c o r d s . 
 
                 f a m i l y   =   a l l o w e d _ g a i _ f a m i l y ( ) 
 
         
 
                 t r y : 
 
                         h o s t . e n c o d e ( " i d n a " ) 
 
                 e x c e p t   U n i c o d e E r r o r : 
 
                         r a i s e   L o c a t i o n P a r s e E r r o r ( f " ' { h o s t } ' ,   l a b e l   e m p t y   o r   t o o   l o n g " )   f r o m   N o n e 
 
         
 
                 f o r   r e s   i n   s o c k e t . g e t a d d r i n f o ( h o s t ,   p o r t ,   f a m i l y ,   s o c k e t . S O C K _ S T R E A M ) : 
 
                         a f ,   s o c k t y p e ,   p r o t o ,   c a n o n n a m e ,   s a   =   r e s 
 
                         s o c k   =   N o n e 
 
                         t r y : 
 
                                 s o c k   =   s o c k e t . s o c k e t ( a f ,   s o c k t y p e ,   p r o t o ) 
 
         
 
                                 #   I f   p r o v i d e d ,   s e t   s o c k e t   l e v e l   o p t i o n s   b e f o r e   c o n n e c t i n g . 
 
                                 _ s e t _ s o c k e t _ o p t i o n s ( s o c k ,   s o c k e t _ o p t i o n s ) 
 
         
 
                                 i f   t i m e o u t   i s   n o t   _ D E F A U L T _ T I M E O U T : 
 
                                         s o c k . s e t t i m e o u t ( t i m e o u t ) 
 
                                 i f   s o u r c e _ a d d r e s s : 
 
                                         s o c k . b i n d ( s o u r c e _ a d d r e s s ) 
 
 >                               s o c k . c o n n e c t ( s a ) 
 
 E                               C o n n e c t i o n R e f u s e d E r r o r :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ c o n n e c t i o n . p y : 7 3 :   C o n n e c t i o n R e f u s e d E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E 7 6 E 4 0 > 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   b o d y   =   N o n e 
 
 h e a d e r s   =   { ' U s e r - A g e n t ' :   ' p y t h o n - r e q u e s t s / 2 . 3 2 . 5 ' ,   ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ,   z s t d ' ,   ' A c c e p t ' :   ' * / * ' ,   ' C o n n e c t i o n ' :   ' k e e p - a l i v e ' } 
 
 r e t r i e s   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 r e d i r e c t   =   F a l s e ,   a s s e r t _ s a m e _ h o s t   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   p o o l _ t i m e o u t   =   N o n e 
 
 r e l e a s e _ c o n n   =   F a l s e ,   c h u n k e d   =   F a l s e ,   b o d y _ p o s   =   N o n e ,   p r e l o a d _ c o n t e n t   =   F a l s e 
 
 d e c o d e _ c o n t e n t   =   F a l s e ,   r e s p o n s e _ k w   =   { } 
 
 p a r s e d _ u r l   =   U r l ( s c h e m e = N o n e ,   a u t h = N o n e ,   h o s t = N o n e ,   p o r t = N o n e ,   p a t h = ' / r e s e t ' ,   q u e r y = N o n e ,   f r a g m e n t = N o n e ) 
 
 d e s t i n a t i o n _ s c h e m e   =   N o n e ,   c o n n   =   N o n e ,   r e l e a s e _ t h i s _ c o n n   =   T r u e 
 
 h t t p _ t u n n e l _ r e q u i r e d   =   F a l s e ,   e r r   =   N o n e ,   c l e a n _ e x i t   =   F a l s e 
 
 
 
         d e f   u r l o p e n (     #   t y p e :   i g n o r e [ o v e r r i d e ] 
 
                 s e l f , 
 
                 m e t h o d :   s t r , 
 
                 u r l :   s t r , 
 
                 b o d y :   _ T Y P E _ B O D Y   |   N o n e   =   N o n e , 
 
                 h e a d e r s :   t y p i n g . M a p p i n g [ s t r ,   s t r ]   |   N o n e   =   N o n e , 
 
                 r e t r i e s :   R e t r y   |   b o o l   |   i n t   |   N o n e   =   N o n e , 
 
                 r e d i r e c t :   b o o l   =   T r u e , 
 
                 a s s e r t _ s a m e _ h o s t :   b o o l   =   T r u e , 
 
                 t i m e o u t :   _ T Y P E _ T I M E O U T   =   _ D E F A U L T _ T I M E O U T , 
 
                 p o o l _ t i m e o u t :   i n t   |   N o n e   =   N o n e , 
 
                 r e l e a s e _ c o n n :   b o o l   |   N o n e   =   N o n e , 
 
                 c h u n k e d :   b o o l   =   F a l s e , 
 
                 b o d y _ p o s :   _ T Y P E _ B O D Y _ P O S I T I O N   |   N o n e   =   N o n e , 
 
                 p r e l o a d _ c o n t e n t :   b o o l   =   T r u e , 
 
                 d e c o d e _ c o n t e n t :   b o o l   =   T r u e , 
 
                 * * r e s p o n s e _ k w :   t y p i n g . A n y , 
 
         )   - >   B a s e H T T P R e s p o n s e : 
 
                 " " " 
 
                 G e t   a   c o n n e c t i o n   f r o m   t h e   p o o l   a n d   p e r f o r m   a n   H T T P   r e q u e s t .   T h i s   i s   t h e 
 
                 l o w e s t   l e v e l   c a l l   f o r   m a k i n g   a   r e q u e s t ,   s o   y o u ' l l   n e e d   t o   s p e c i f y   a l l 
 
                 t h e   r a w   d e t a i l s . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       M o r e   c o m m o n l y ,   i t ' s   a p p r o p r i a t e   t o   u s e   a   c o n v e n i e n c e   m e t h o d 
 
                       s u c h   a s   : m e t h : ` r e q u e s t ` . 
 
         
 
                 . .   n o t e : : 
 
         
 
                       ` r e l e a s e _ c o n n `   w i l l   o n l y   b e h a v e   a s   e x p e c t e d   i f 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   b e c a u s e   w e   w a n t   t o   m a k e 
 
                       ` p r e l o a d _ c o n t e n t = F a l s e `   t h e   d e f a u l t   b e h a v i o u r   s o m e d a y   s o o n   w i t h o u t 
 
                       b r e a k i n g   b a c k w a r d s   c o m p a t i b i l i t y . 
 
         
 
                 : p a r a m   m e t h o d : 
 
                         H T T P   r e q u e s t   m e t h o d   ( s u c h   a s   G E T ,   P O S T ,   P U T ,   e t c . ) 
 
         
 
                 : p a r a m   u r l : 
 
                         T h e   U R L   t o   p e r f o r m   t h e   r e q u e s t   o n . 
 
         
 
                 : p a r a m   b o d y : 
 
                         D a t a   t o   s e n d   i n   t h e   r e q u e s t   b o d y ,   e i t h e r   : c l a s s : ` s t r ` ,   : c l a s s : ` b y t e s ` , 
 
                         a n   i t e r a b l e   o f   : c l a s s : ` s t r ` / : c l a s s : ` b y t e s ` ,   o r   a   f i l e - l i k e   o b j e c t . 
 
         
 
                 : p a r a m   h e a d e r s : 
 
                         D i c t i o n a r y   o f   c u s t o m   h e a d e r s   t o   s e n d ,   s u c h   a s   U s e r - A g e n t , 
 
                         I f - N o n e - M a t c h ,   e t c .   I f   N o n e ,   p o o l   h e a d e r s   a r e   u s e d .   I f   p r o v i d e d , 
 
                         t h e s e   h e a d e r s   c o m p l e t e l y   r e p l a c e   a n y   p o o l - s p e c i f i c   h e a d e r s . 
 
         
 
                 : p a r a m   r e t r i e s : 
 
                         C o n f i g u r e   t h e   n u m b e r   o f   r e t r i e s   t o   a l l o w   b e f o r e   r a i s i n g   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r `   e x c e p t i o n . 
 
         
 
                         I f   ` ` N o n e ` `   ( d e f a u l t )   w i l l   r e t r y   3   t i m e s ,   s e e   ` ` R e t r y . D E F A U L T ` ` .   P a s s   a 
 
                         : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y `   o b j e c t   f o r   f i n e - g r a i n e d   c o n t r o l 
 
                         o v e r   d i f f e r e n t   t y p e s   o f   r e t r i e s . 
 
                         P a s s   a n   i n t e g e r   n u m b e r   t o   r e t r y   c o n n e c t i o n   e r r o r s   t h a t   m a n y   t i m e s , 
 
                         b u t   n o   o t h e r   t y p e s   o f   e r r o r s .   P a s s   z e r o   t o   n e v e r   r e t r y . 
 
         
 
                         I f   ` ` F a l s e ` ` ,   t h e n   r e t r i e s   a r e   d i s a b l e d   a n d   a n y   e x c e p t i o n   i s   r a i s e d 
 
                         i m m e d i a t e l y .   A l s o ,   i n s t e a d   o f   r a i s i n g   a   M a x R e t r y E r r o r   o n   r e d i r e c t s , 
 
                         t h e   r e d i r e c t   r e s p o n s e   w i l l   b e   r e t u r n e d . 
 
         
 
                 : t y p e   r e t r i e s :   : c l a s s : ` ~ u r l l i b 3 . u t i l . r e t r y . R e t r y ` ,   F a l s e ,   o r   a n   i n t . 
 
         
 
                 : p a r a m   r e d i r e c t : 
 
                         I f   T r u e ,   a u t o m a t i c a l l y   h a n d l e   r e d i r e c t s   ( s t a t u s   c o d e s   3 0 1 ,   3 0 2 , 
 
                         3 0 3 ,   3 0 7 ,   3 0 8 ) .   E a c h   r e d i r e c t   c o u n t s   a s   a   r e t r y .   D i s a b l i n g   r e t r i e s 
 
                         w i l l   d i s a b l e   r e d i r e c t ,   t o o . 
 
         
 
                 : p a r a m   a s s e r t _ s a m e _ h o s t : 
 
                         I f   ` ` T r u e ` ` ,   w i l l   m a k e   s u r e   t h a t   t h e   h o s t   o f   t h e   p o o l   r e q u e s t s   i s 
 
                         c o n s i s t e n t   e l s e   w i l l   r a i s e   H o s t C h a n g e d E r r o r .   W h e n   ` ` F a l s e ` ` ,   y o u   c a n 
 
                         u s e   t h e   p o o l   o n   a n   H T T P   p r o x y   a n d   r e q u e s t   f o r e i g n   h o s t s . 
 
         
 
                 : p a r a m   t i m e o u t : 
 
                         I f   s p e c i f i e d ,   o v e r r i d e s   t h e   d e f a u l t   t i m e o u t   f o r   t h i s   o n e 
 
                         r e q u e s t .   I t   m a y   b e   a   f l o a t   ( i n   s e c o n d s )   o r   a n   i n s t a n c e   o f 
 
                         : c l a s s : ` u r l l i b 3 . u t i l . T i m e o u t ` . 
 
         
 
                 : p a r a m   p o o l _ t i m e o u t : 
 
                         I f   s e t   a n d   t h e   p o o l   i s   s e t   t o   b l o c k = T r u e ,   t h e n   t h i s   m e t h o d   w i l l 
 
                         b l o c k   f o r   ` ` p o o l _ t i m e o u t ` `   s e c o n d s   a n d   r a i s e   E m p t y P o o l E r r o r   i f   n o 
 
                         c o n n e c t i o n   i s   a v a i l a b l e   w i t h i n   t h e   t i m e   p e r i o d . 
 
         
 
                 : p a r a m   b o o l   p r e l o a d _ c o n t e n t : 
 
                         I f   T r u e ,   t h e   r e s p o n s e ' s   b o d y   w i l l   b e   p r e l o a d e d   i n t o   m e m o r y . 
 
         
 
                 : p a r a m   b o o l   d e c o d e _ c o n t e n t : 
 
                         I f   T r u e ,   w i l l   a t t e m p t   t o   d e c o d e   t h e   b o d y   b a s e d   o n   t h e 
 
                         ' c o n t e n t - e n c o d i n g '   h e a d e r . 
 
         
 
                 : p a r a m   r e l e a s e _ c o n n : 
 
                         I f   F a l s e ,   t h e n   t h e   u r l o p e n   c a l l   w i l l   n o t   r e l e a s e   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l   o n c e   a   r e s p o n s e   i s   r e c e i v e d   ( b u t   w i l l   r e l e a s e   i f 
 
                         y o u   r e a d   t h e   e n t i r e   c o n t e n t s   o f   t h e   r e s p o n s e   s u c h   a s   w h e n 
 
                         ` p r e l o a d _ c o n t e n t = T r u e ` ) .   T h i s   i s   u s e f u l   i f   y o u ' r e   n o t   p r e l o a d i n g 
 
                         t h e   r e s p o n s e ' s   c o n t e n t   i m m e d i a t e l y .   Y o u   w i l l   n e e d   t o   c a l l 
 
                         ` ` r . r e l e a s e _ c o n n ( ) ` `   o n   t h e   r e s p o n s e   ` ` r ` `   t o   r e t u r n   t h e   c o n n e c t i o n 
 
                         b a c k   i n t o   t h e   p o o l .   I f   N o n e ,   i t   t a k e s   t h e   v a l u e   o f   ` ` p r e l o a d _ c o n t e n t ` ` 
 
                         w h i c h   d e f a u l t s   t o   ` ` T r u e ` ` . 
 
         
 
                 : p a r a m   b o o l   c h u n k e d : 
 
                         I f   T r u e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   c h u n k e d   t r a n s f e r 
 
                         e n c o d i n g .   O t h e r w i s e ,   u r l l i b 3   w i l l   s e n d   t h e   b o d y   u s i n g   t h e   s t a n d a r d 
 
                         c o n t e n t - l e n g t h   f o r m .   D e f a u l t s   t o   F a l s e . 
 
         
 
                 : p a r a m   i n t   b o d y _ p o s : 
 
                         P o s i t i o n   t o   s e e k   t o   i n   f i l e - l i k e   b o d y   i n   t h e   e v e n t   o f   a   r e t r y   o r 
 
                         r e d i r e c t .   T y p i c a l l y   t h i s   w o n ' t   n e e d   t o   b e   s e t   b e c a u s e   u r l l i b 3   w i l l 
 
                         a u t o - p o p u l a t e   t h e   v a l u e   w h e n   n e e d e d . 
 
                 " " " 
 
                 p a r s e d _ u r l   =   p a r s e _ u r l ( u r l ) 
 
                 d e s t i n a t i o n _ s c h e m e   =   p a r s e d _ u r l . s c h e m e 
 
         
 
                 i f   h e a d e r s   i s   N o n e : 
 
                         h e a d e r s   =   s e l f . h e a d e r s 
 
         
 
                 i f   n o t   i s i n s t a n c e ( r e t r i e s ,   R e t r y ) : 
 
                         r e t r i e s   =   R e t r y . f r o m _ i n t ( r e t r i e s ,   r e d i r e c t = r e d i r e c t ,   d e f a u l t = s e l f . r e t r i e s ) 
 
         
 
                 i f   r e l e a s e _ c o n n   i s   N o n e : 
 
                         r e l e a s e _ c o n n   =   p r e l o a d _ c o n t e n t 
 
         
 
                 #   C h e c k   h o s t 
 
                 i f   a s s e r t _ s a m e _ h o s t   a n d   n o t   s e l f . i s _ s a m e _ h o s t ( u r l ) : 
 
                         r a i s e   H o s t C h a n g e d E r r o r ( s e l f ,   u r l ,   r e t r i e s ) 
 
         
 
                 #   E n s u r e   t h a t   t h e   U R L   w e ' r e   c o n n e c t i n g   t o   i s   p r o p e r l y   e n c o d e d 
 
                 i f   u r l . s t a r t s w i t h ( " / " ) : 
 
                         u r l   =   t o _ s t r ( _ e n c o d e _ t a r g e t ( u r l ) ) 
 
                 e l s e : 
 
                         u r l   =   t o _ s t r ( p a r s e d _ u r l . u r l ) 
 
         
 
                 c o n n   =   N o n e 
 
         
 
                 #   T r a c k   w h e t h e r   ` c o n n `   n e e d s   t o   b e   r e l e a s e d   b e f o r e 
 
                 #   r e t u r n i n g / r a i s i n g / r e c u r s i n g .   U p d a t e   t h i s   v a r i a b l e   i f   n e c e s s a r y ,   a n d 
 
                 #   l e a v e   ` r e l e a s e _ c o n n `   c o n s t a n t   t h r o u g h o u t   t h e   f u n c t i o n .   T h a t   w a y ,   i f 
 
                 #   t h e   f u n c t i o n   r e c u r s e s ,   t h e   o r i g i n a l   v a l u e   o f   ` r e l e a s e _ c o n n `   w i l l   b e 
 
                 #   p a s s e d   d o w n   i n t o   t h e   r e c u r s i v e   c a l l ,   a n d   i t s   v a l u e   w i l l   b e   r e s p e c t e d . 
 
                 # 
 
                 #   S e e   i s s u e   # 6 5 1   [ 1 ]   f o r   d e t a i l s . 
 
                 # 
 
                 #   [ 1 ]   < h t t p s : / / g i t h u b . c o m / u r l l i b 3 / u r l l i b 3 / i s s u e s / 6 5 1 > 
 
                 r e l e a s e _ t h i s _ c o n n   =   r e l e a s e _ c o n n 
 
         
 
                 h t t p _ t u n n e l _ r e q u i r e d   =   c o n n e c t i o n _ r e q u i r e s _ h t t p _ t u n n e l ( 
 
                         s e l f . p r o x y ,   s e l f . p r o x y _ c o n f i g ,   d e s t i n a t i o n _ s c h e m e 
 
                 ) 
 
         
 
                 #   M e r g e   t h e   p r o x y   h e a d e r s .   O n l y   d o n e   w h e n   n o t   u s i n g   H T T P   C O N N E C T .   W e 
 
                 #   h a v e   t o   c o p y   t h e   h e a d e r s   d i c t   s o   w e   c a n   s a f e l y   c h a n g e   i t   w i t h o u t   t h o s e 
 
                 #   c h a n g e s   b e i n g   r e f l e c t e d   i n   a n y o n e   e l s e ' s   c o p y . 
 
                 i f   n o t   h t t p _ t u n n e l _ r e q u i r e d : 
 
                         h e a d e r s   =   h e a d e r s . c o p y ( )     #   t y p e :   i g n o r e [ a t t r - d e f i n e d ] 
 
                         h e a d e r s . u p d a t e ( s e l f . p r o x y _ h e a d e r s )     #   t y p e :   i g n o r e [ u n i o n - a t t r ] 
 
         
 
                 #   M u s t   k e e p   t h e   e x c e p t i o n   b o u n d   t o   a   s e p a r a t e   v a r i a b l e   o r   e l s e   P y t h o n   3 
 
                 #   c o m p l a i n s   a b o u t   U n b o u n d L o c a l E r r o r . 
 
                 e r r   =   N o n e 
 
         
 
                 #   K e e p   t r a c k   o f   w h e t h e r   w e   c l e a n l y   e x i t e d   t h e   e x c e p t   b l o c k .   T h i s 
 
                 #   e n s u r e s   w e   d o   p r o p e r   c l e a n u p   i n   f i n a l l y . 
 
                 c l e a n _ e x i t   =   F a l s e 
 
         
 
                 #   R e w i n d   b o d y   p o s i t i o n ,   i f   n e e d e d .   R e c o r d   c u r r e n t   p o s i t i o n 
 
                 #   f o r   f u t u r e   r e w i n d s   i n   t h e   e v e n t   o f   a   r e d i r e c t / r e t r y . 
 
                 b o d y _ p o s   =   s e t _ f i l e _ p o s i t i o n ( b o d y ,   b o d y _ p o s ) 
 
         
 
                 t r y : 
 
                         #   R e q u e s t   a   c o n n e c t i o n   f r o m   t h e   q u e u e . 
 
                         t i m e o u t _ o b j   =   s e l f . _ g e t _ t i m e o u t ( t i m e o u t ) 
 
                         c o n n   =   s e l f . _ g e t _ c o n n ( t i m e o u t = p o o l _ t i m e o u t ) 
 
         
 
                         c o n n . t i m e o u t   =   t i m e o u t _ o b j . c o n n e c t _ t i m e o u t     #   t y p e :   i g n o r e [ a s s i g n m e n t ] 
 
         
 
                         #   I s   t h i s   a   c l o s e d / n e w   c o n n e c t i o n   t h a t   r e q u i r e s   C O N N E C T   t u n n e l l i n g ? 
 
                         i f   s e l f . p r o x y   i s   n o t   N o n e   a n d   h t t p _ t u n n e l _ r e q u i r e d   a n d   c o n n . i s _ c l o s e d : 
 
                                 t r y : 
 
                                         s e l f . _ p r e p a r e _ p r o x y ( c o n n ) 
 
                                 e x c e p t   ( B a s e S S L E r r o r ,   O S E r r o r ,   S o c k e t T i m e o u t )   a s   e : 
 
                                         s e l f . _ r a i s e _ t i m e o u t ( 
 
                                                 e r r = e ,   u r l = s e l f . p r o x y . u r l ,   t i m e o u t _ v a l u e = c o n n . t i m e o u t 
 
                                         ) 
 
                                         r a i s e 
 
         
 
                         #   I f   w e ' r e   g o i n g   t o   r e l e a s e   t h e   c o n n e c t i o n   i n   ` ` f i n a l l y : ` ` ,   t h e n 
 
                         #   t h e   r e s p o n s e   d o e s n ' t   n e e d   t o   k n o w   a b o u t   t h e   c o n n e c t i o n .   O t h e r w i s e 
 
                         #   i t   w i l l   a l s o   t r y   t o   r e l e a s e   i t   a n d   w e ' l l   h a v e   a   d o u b l e - r e l e a s e 
 
                         #   m e s s . 
 
                         r e s p o n s e _ c o n n   =   c o n n   i f   n o t   r e l e a s e _ c o n n   e l s e   N o n e 
 
         
 
                         #   M a k e   t h e   r e q u e s t   o n   t h e   H T T P C o n n e c t i o n   o b j e c t 
 
 >                       r e s p o n s e   =   s e l f . _ m a k e _ r e q u e s t ( 
 
                                 c o n n , 
 
                                 m e t h o d , 
 
                                 u r l , 
 
                                 t i m e o u t = t i m e o u t _ o b j , 
 
                                 b o d y = b o d y , 
 
                                 h e a d e r s = h e a d e r s , 
 
                                 c h u n k e d = c h u n k e d , 
 
                                 r e t r i e s = r e t r i e s , 
 
                                 r e s p o n s e _ c o n n = r e s p o n s e _ c o n n , 
 
                                 p r e l o a d _ c o n t e n t = p r e l o a d _ c o n t e n t , 
 
                                 d e c o d e _ c o n t e n t = d e c o d e _ c o n t e n t , 
 
                                 * * r e s p o n s e _ k w , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 7 8 7 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 4 9 3 :   i n   _ m a k e _ r e q u e s t 
 
         c o n n . r e q u e s t ( 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 4 9 4 :   i n   r e q u e s t 
 
         s e l f . e n d h e a d e r s ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 3 3 3 :   i n   e n d h e a d e r s 
 
         s e l f . _ s e n d _ o u t p u t ( m e s s a g e _ b o d y ,   e n c o d e _ c h u n k e d = e n c o d e _ c h u n k e d ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 9 3 :   i n   _ s e n d _ o u t p u t 
 
         s e l f . s e n d ( m s g ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ h t t p \ c l i e n t . p y : 1 0 3 7 :   i n   s e n d 
 
         s e l f . c o n n e c t ( ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 3 2 5 :   i n   c o n n e c t 
 
         s e l f . s o c k   =   s e l f . _ n e w _ c o n n ( ) 
 
                                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D B F 0 > 
 
 
 
         d e f   _ n e w _ c o n n ( s e l f )   - >   s o c k e t . s o c k e t : 
 
                 " " " E s t a b l i s h   a   s o c k e t   c o n n e c t i o n   a n d   s e t   n o d e l a y   s e t t i n g s   o n   i t . 
 
         
 
                 : r e t u r n :   N e w   s o c k e t   c o n n e c t i o n . 
 
                 " " " 
 
                 t r y : 
 
                         s o c k   =   c o n n e c t i o n . c r e a t e _ c o n n e c t i o n ( 
 
                                 ( s e l f . _ d n s _ h o s t ,   s e l f . p o r t ) , 
 
                                 s e l f . t i m e o u t , 
 
                                 s o u r c e _ a d d r e s s = s e l f . s o u r c e _ a d d r e s s , 
 
                                 s o c k e t _ o p t i o n s = s e l f . s o c k e t _ o p t i o n s , 
 
                         ) 
 
                 e x c e p t   s o c k e t . g a i e r r o r   a s   e : 
 
                         r a i s e   N a m e R e s o l u t i o n E r r o r ( s e l f . h o s t ,   s e l f ,   e )   f r o m   e 
 
                 e x c e p t   S o c k e t T i m e o u t   a s   e : 
 
                         r a i s e   C o n n e c t T i m e o u t E r r o r ( 
 
                                 s e l f , 
 
                                 f " C o n n e c t i o n   t o   { s e l f . h o s t }   t i m e d   o u t .   ( c o n n e c t   t i m e o u t = { s e l f . t i m e o u t } ) " , 
 
                         )   f r o m   e 
 
         
 
                 e x c e p t   O S E r r o r   a s   e : 
 
 >                       r a i s e   N e w C o n n e c t i o n E r r o r ( 
 
                                 s e l f ,   f " F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   { e } " 
 
                         )   f r o m   e 
 
 E                       u r l l i b 3 . e x c e p t i o n s . N e w C o n n e c t i o n E r r o r :   < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D B F 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n . p y : 2 1 3 :   N e w C o n n e c t i o n E r r o r 
 
 
 
 T h e   a b o v e   e x c e p t i o n   w a s   t h e   d i r e c t   c a u s e   o f   t h e   f o l l o w i n g   e x c e p t i o n : 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 6 A B 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
 >                       r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 4 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ c o n n e c t i o n p o o l . p y : 8 4 1 :   i n   u r l o p e n 
 
         r e t r i e s   =   r e t r i e s . i n c r e m e n t ( 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   R e t r y ( t o t a l = 0 ,   c o n n e c t = N o n e ,   r e a d = F a l s e ,   r e d i r e c t = N o n e ,   s t a t u s = N o n e ) 
 
 m e t h o d   =   ' G E T ' ,   u r l   =   ' / r e s e t ' ,   r e s p o n s e   =   N o n e 
 
 e r r o r   =   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D B F 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) 
 
 _ p o o l   =   < u r l l i b 3 . c o n n e c t i o n p o o l . H T T P C o n n e c t i o n P o o l   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 E 7 6 E 4 0 > 
 
 _ s t a c k t r a c e   =   < t r a c e b a c k   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 8 2 8 1 D 0 0 > 
 
 
 
         d e f   i n c r e m e n t ( 
 
                 s e l f , 
 
                 m e t h o d :   s t r   |   N o n e   =   N o n e , 
 
                 u r l :   s t r   |   N o n e   =   N o n e , 
 
                 r e s p o n s e :   B a s e H T T P R e s p o n s e   |   N o n e   =   N o n e , 
 
                 e r r o r :   E x c e p t i o n   |   N o n e   =   N o n e , 
 
                 _ p o o l :   C o n n e c t i o n P o o l   |   N o n e   =   N o n e , 
 
                 _ s t a c k t r a c e :   T r a c e b a c k T y p e   |   N o n e   =   N o n e , 
 
         )   - >   S e l f : 
 
                 " " " R e t u r n   a   n e w   R e t r y   o b j e c t   w i t h   i n c r e m e n t e d   r e t r y   c o u n t e r s . 
 
         
 
                 : p a r a m   r e s p o n s e :   A   r e s p o n s e   o b j e c t ,   o r   N o n e ,   i f   t h e   s e r v e r   d i d   n o t 
 
                         r e t u r n   a   r e s p o n s e . 
 
                 : t y p e   r e s p o n s e :   : c l a s s : ` ~ u r l l i b 3 . r e s p o n s e . B a s e H T T P R e s p o n s e ` 
 
                 : p a r a m   E x c e p t i o n   e r r o r :   A n   e r r o r   e n c o u n t e r e d   d u r i n g   t h e   r e q u e s t ,   o r 
 
                         N o n e   i f   t h e   r e s p o n s e   w a s   r e c e i v e d   s u c c e s s f u l l y . 
 
         
 
                 : r e t u r n :   A   n e w   ` ` R e t r y ` `   o b j e c t . 
 
                 " " " 
 
                 i f   s e l f . t o t a l   i s   F a l s e   a n d   e r r o r : 
 
                         #   D i s a b l e d ,   i n d i c a t e   t o   r e - r a i s e   t h e   e r r o r . 
 
                         r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
         
 
                 t o t a l   =   s e l f . t o t a l 
 
                 i f   t o t a l   i s   n o t   N o n e : 
 
                         t o t a l   - =   1 
 
         
 
                 c o n n e c t   =   s e l f . c o n n e c t 
 
                 r e a d   =   s e l f . r e a d 
 
                 r e d i r e c t   =   s e l f . r e d i r e c t 
 
                 s t a t u s _ c o u n t   =   s e l f . s t a t u s 
 
                 o t h e r   =   s e l f . o t h e r 
 
                 c a u s e   =   " u n k n o w n " 
 
                 s t a t u s   =   N o n e 
 
                 r e d i r e c t _ l o c a t i o n   =   N o n e 
 
         
 
                 i f   e r r o r   a n d   s e l f . _ i s _ c o n n e c t i o n _ e r r o r ( e r r o r ) : 
 
                         #   C o n n e c t   r e t r y ? 
 
                         i f   c o n n e c t   i s   F a l s e : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   c o n n e c t   i s   n o t   N o n e : 
 
                                 c o n n e c t   - =   1 
 
         
 
                 e l i f   e r r o r   a n d   s e l f . _ i s _ r e a d _ e r r o r ( e r r o r ) : 
 
                         #   R e a d   r e t r y ? 
 
                         i f   r e a d   i s   F a l s e   o r   m e t h o d   i s   N o n e   o r   n o t   s e l f . _ i s _ m e t h o d _ r e t r y a b l e ( m e t h o d ) : 
 
                                 r a i s e   r e r a i s e ( t y p e ( e r r o r ) ,   e r r o r ,   _ s t a c k t r a c e ) 
 
                         e l i f   r e a d   i s   n o t   N o n e : 
 
                                 r e a d   - =   1 
 
         
 
                 e l i f   e r r o r : 
 
                         #   O t h e r   r e t r y ? 
 
                         i f   o t h e r   i s   n o t   N o n e : 
 
                                 o t h e r   - =   1 
 
         
 
                 e l i f   r e s p o n s e   a n d   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) : 
 
                         #   R e d i r e c t   r e t r y ? 
 
                         i f   r e d i r e c t   i s   n o t   N o n e : 
 
                                 r e d i r e c t   - =   1 
 
                         c a u s e   =   " t o o   m a n y   r e d i r e c t s " 
 
                         r e s p o n s e _ r e d i r e c t _ l o c a t i o n   =   r e s p o n s e . g e t _ r e d i r e c t _ l o c a t i o n ( ) 
 
                         i f   r e s p o n s e _ r e d i r e c t _ l o c a t i o n : 
 
                                 r e d i r e c t _ l o c a t i o n   =   r e s p o n s e _ r e d i r e c t _ l o c a t i o n 
 
                         s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 e l s e : 
 
                         #   I n c r e m e n t i n g   b e c a u s e   o f   a   s e r v e r   e r r o r   l i k e   a   5 0 0   i n 
 
                         #   s t a t u s _ f o r c e l i s t   a n d   t h e   g i v e n   m e t h o d   i s   i n   t h e   a l l o w e d _ m e t h o d s 
 
                         c a u s e   =   R e s p o n s e E r r o r . G E N E R I C _ E R R O R 
 
                         i f   r e s p o n s e   a n d   r e s p o n s e . s t a t u s : 
 
                                 i f   s t a t u s _ c o u n t   i s   n o t   N o n e : 
 
                                         s t a t u s _ c o u n t   - =   1 
 
                                 c a u s e   =   R e s p o n s e E r r o r . S P E C I F I C _ E R R O R . f o r m a t ( s t a t u s _ c o d e = r e s p o n s e . s t a t u s ) 
 
                                 s t a t u s   =   r e s p o n s e . s t a t u s 
 
         
 
                 h i s t o r y   =   s e l f . h i s t o r y   +   ( 
 
                         R e q u e s t H i s t o r y ( m e t h o d ,   u r l ,   e r r o r ,   s t a t u s ,   r e d i r e c t _ l o c a t i o n ) , 
 
                 ) 
 
         
 
                 n e w _ r e t r y   =   s e l f . n e w ( 
 
                         t o t a l = t o t a l , 
 
                         c o n n e c t = c o n n e c t , 
 
                         r e a d = r e a d , 
 
                         r e d i r e c t = r e d i r e c t , 
 
                         s t a t u s = s t a t u s _ c o u n t , 
 
                         o t h e r = o t h e r , 
 
                         h i s t o r y = h i s t o r y , 
 
                 ) 
 
         
 
                 i f   n e w _ r e t r y . i s _ e x h a u s t e d ( ) : 
 
                         r e a s o n   =   e r r o r   o r   R e s p o n s e E r r o r ( c a u s e ) 
 
 >                       r a i s e   M a x R e t r y E r r o r ( _ p o o l ,   u r l ,   r e a s o n )   f r o m   r e a s o n     #   t y p e :   i g n o r e [ a r g - t y p e ] 
 
                         ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 E                       u r l l i b 3 . e x c e p t i o n s . M a x R e t r y E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D B F 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ u r l l i b 3 \ u t i l \ r e t r y . p y : 5 1 9 :   M a x R e t r y E r r o r 
 
 
 
 D u r i n g   h a n d l i n g   o f   t h e   a b o v e   e x c e p t i o n ,   a n o t h e r   e x c e p t i o n   o c c u r r e d : 
 
 
 
         @ p y t e s t . f i x t u r e ( a u t o u s e = T r u e ) 
 
         d e f   r e s e t _ c o u n t e r ( ) : 
 
 >               r e s e t ( ) 
 
 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 2 4 :   
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 t e s t s \ t e s t _ r e s i l i e n c e . p y : 1 7 :   i n   r e s e t 
 
         r e q u e s t s . g e t ( f " { B A S E } / r e s e t " ) 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 7 3 :   i n   g e t 
 
         r e t u r n   r e q u e s t ( " g e t " ,   u r l ,   p a r a m s = p a r a m s ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a p i . p y : 5 9 :   i n   r e q u e s t 
 
         r e t u r n   s e s s i o n . r e q u e s t ( m e t h o d = m e t h o d ,   u r l = u r l ,   * * k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 5 8 9 :   i n   r e q u e s t 
 
         r e s p   =   s e l f . s e n d ( p r e p ,   * * s e n d _ k w a r g s ) 
 
                       ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ s e s s i o n s . p y : 7 0 3 :   i n   s e n d 
 
         r   =   a d a p t e r . s e n d ( r e q u e s t ,   * * k w a r g s ) 
 
                 ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 
 
 _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _   _ 
 
 
 
 s e l f   =   < r e q u e s t s . a d a p t e r s . H T T P A d a p t e r   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 6 A B 5 0 > 
 
 r e q u e s t   =   < P r e p a r e d R e q u e s t   [ G E T ] > ,   s t r e a m   =   F a l s e 
 
 t i m e o u t   =   T i m e o u t ( c o n n e c t = N o n e ,   r e a d = N o n e ,   t o t a l = N o n e ) ,   v e r i f y   =   T r u e 
 
 c e r t   =   N o n e ,   p r o x i e s   =   O r d e r e d D i c t ( ) 
 
 
 
         d e f   s e n d ( 
 
                 s e l f ,   r e q u e s t ,   s t r e a m = F a l s e ,   t i m e o u t = N o n e ,   v e r i f y = T r u e ,   c e r t = N o n e ,   p r o x i e s = N o n e 
 
         ) : 
 
                 " " " S e n d s   P r e p a r e d R e q u e s t   o b j e c t .   R e t u r n s   R e s p o n s e   o b j e c t . 
 
         
 
                 : p a r a m   r e q u e s t :   T h e   : c l a s s : ` P r e p a r e d R e q u e s t   < P r e p a r e d R e q u e s t > `   b e i n g   s e n t . 
 
                 : p a r a m   s t r e a m :   ( o p t i o n a l )   W h e t h e r   t o   s t r e a m   t h e   r e q u e s t   c o n t e n t . 
 
                 : p a r a m   t i m e o u t :   ( o p t i o n a l )   H o w   l o n g   t o   w a i t   f o r   t h e   s e r v e r   t o   s e n d 
 
                         d a t a   b e f o r e   g i v i n g   u p ,   a s   a   f l o a t ,   o r   a   : r e f : ` ( c o n n e c t   t i m e o u t , 
 
                         r e a d   t i m e o u t )   < t i m e o u t s > `   t u p l e . 
 
                 : t y p e   t i m e o u t :   f l o a t   o r   t u p l e   o r   u r l l i b 3   T i m e o u t   o b j e c t 
 
                 : p a r a m   v e r i f y :   ( o p t i o n a l )   E i t h e r   a   b o o l e a n ,   i n   w h i c h   c a s e   i t   c o n t r o l s   w h e t h e r 
 
                         w e   v e r i f y   t h e   s e r v e r ' s   T L S   c e r t i f i c a t e ,   o r   a   s t r i n g ,   i n   w h i c h   c a s e   i t 
 
                         m u s t   b e   a   p a t h   t o   a   C A   b u n d l e   t o   u s e 
 
                 : p a r a m   c e r t :   ( o p t i o n a l )   A n y   u s e r - p r o v i d e d   S S L   c e r t i f i c a t e   t o   b e   t r u s t e d . 
 
                 : p a r a m   p r o x i e s :   ( o p t i o n a l )   T h e   p r o x i e s   d i c t i o n a r y   t o   a p p l y   t o   t h e   r e q u e s t . 
 
                 : r t y p e :   r e q u e s t s . R e s p o n s e 
 
                 " " " 
 
         
 
                 t r y : 
 
                         c o n n   =   s e l f . g e t _ c o n n e c t i o n _ w i t h _ t l s _ c o n t e x t ( 
 
                                 r e q u e s t ,   v e r i f y ,   p r o x i e s = p r o x i e s ,   c e r t = c e r t 
 
                         ) 
 
                 e x c e p t   L o c a t i o n V a l u e E r r o r   a s   e : 
 
                         r a i s e   I n v a l i d U R L ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 s e l f . c e r t _ v e r i f y ( c o n n ,   r e q u e s t . u r l ,   v e r i f y ,   c e r t ) 
 
                 u r l   =   s e l f . r e q u e s t _ u r l ( r e q u e s t ,   p r o x i e s ) 
 
                 s e l f . a d d _ h e a d e r s ( 
 
                         r e q u e s t , 
 
                         s t r e a m = s t r e a m , 
 
                         t i m e o u t = t i m e o u t , 
 
                         v e r i f y = v e r i f y , 
 
                         c e r t = c e r t , 
 
                         p r o x i e s = p r o x i e s , 
 
                 ) 
 
         
 
                 c h u n k e d   =   n o t   ( r e q u e s t . b o d y   i s   N o n e   o r   " C o n t e n t - L e n g t h "   i n   r e q u e s t . h e a d e r s ) 
 
         
 
                 i f   i s i n s t a n c e ( t i m e o u t ,   t u p l e ) : 
 
                         t r y : 
 
                                 c o n n e c t ,   r e a d   =   t i m e o u t 
 
                                 t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = c o n n e c t ,   r e a d = r e a d ) 
 
                         e x c e p t   V a l u e E r r o r : 
 
                                 r a i s e   V a l u e E r r o r ( 
 
                                         f " I n v a l i d   t i m e o u t   { t i m e o u t } .   P a s s   a   ( c o n n e c t ,   r e a d )   t i m e o u t   t u p l e ,   " 
 
                                         f " o r   a   s i n g l e   f l o a t   t o   s e t   b o t h   t i m e o u t s   t o   t h e   s a m e   v a l u e . " 
 
                                 ) 
 
                 e l i f   i s i n s t a n c e ( t i m e o u t ,   T i m e o u t S a u c e ) : 
 
                         p a s s 
 
                 e l s e : 
 
                         t i m e o u t   =   T i m e o u t S a u c e ( c o n n e c t = t i m e o u t ,   r e a d = t i m e o u t ) 
 
         
 
                 t r y : 
 
                         r e s p   =   c o n n . u r l o p e n ( 
 
                                 m e t h o d = r e q u e s t . m e t h o d , 
 
                                 u r l = u r l , 
 
                                 b o d y = r e q u e s t . b o d y , 
 
                                 h e a d e r s = r e q u e s t . h e a d e r s , 
 
                                 r e d i r e c t = F a l s e , 
 
                                 a s s e r t _ s a m e _ h o s t = F a l s e , 
 
                                 p r e l o a d _ c o n t e n t = F a l s e , 
 
                                 d e c o d e _ c o n t e n t = F a l s e , 
 
                                 r e t r i e s = s e l f . m a x _ r e t r i e s , 
 
                                 t i m e o u t = t i m e o u t , 
 
                                 c h u n k e d = c h u n k e d , 
 
                         ) 
 
         
 
                 e x c e p t   ( P r o t o c o l E r r o r ,   O S E r r o r )   a s   e r r : 
 
                         r a i s e   C o n n e c t i o n E r r o r ( e r r ,   r e q u e s t = r e q u e s t ) 
 
         
 
                 e x c e p t   M a x R e t r y E r r o r   a s   e : 
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   C o n n e c t T i m e o u t E r r o r ) : 
 
                                 #   T O D O :   R e m o v e   t h i s   i n   3 . 0 . 0 :   s e e   # 2 8 1 1 
 
                                 i f   n o t   i s i n s t a n c e ( e . r e a s o n ,   N e w C o n n e c t i o n E r r o r ) : 
 
                                         r a i s e   C o n n e c t T i m e o u t ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   R e s p o n s e E r r o r ) : 
 
                                 r a i s e   R e t r y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ P r o x y E r r o r ) : 
 
                                 r a i s e   P r o x y E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
                         i f   i s i n s t a n c e ( e . r e a s o n ,   _ S S L E r r o r ) : 
 
                                 #   T h i s   b r a n c h   i s   f o r   u r l l i b 3   v 1 . 2 2   a n d   l a t e r . 
 
                                 r a i s e   S S L E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
         
 
 >                       r a i s e   C o n n e c t i o n E r r o r ( e ,   r e q u e s t = r e q u e s t ) 
 
 E                       r e q u e s t s . e x c e p t i o n s . C o n n e c t i o n E r r o r :   H T T P C o n n e c t i o n P o o l ( h o s t = ' l o c a l h o s t ' ,   p o r t = 3 0 0 1 ) :   M a x   r e t r i e s   e x c e e d e d   w i t h   u r l :   / r e s e t   ( C a u s e d   b y   N e w C o n n e c t i o n E r r o r ( ' < u r l l i b 3 . c o n n e c t i o n . H T T P C o n n e c t i o n   o b j e c t   a t   0 x 0 0 0 0 0 2 4 B 0 6 F 2 D B F 0 > :   F a i l e d   t o   e s t a b l i s h   a   n e w   c o n n e c t i o n :   [ W i n E r r o r   1 0 0 6 1 ]   N o   c o n n e c t i o n   c o u l d   b e   m a d e   b e c a u s e   t h e   t a r g e t   m a c h i n e   a c t i v e l y   r e f u s e d   i t ' ) ) 
 
 
 
 . . \ . . \ . . \ . . \ A p p D a t a \ L o c a l \ P r o g r a m s \ P y t h o n \ P y t h o n 3 1 4 \ L i b \ s i t e - p a c k a g e s \ r e q u e s t s \ a d a p t e r s . p y : 6 7 7 :   C o n n e c t i o n E r r o r 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =   w a r n i n g s   s u m m a r y   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ d e d u p l i c a t i o n _ d i s a b l e d _ b y _ d e f a u l t 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ c o n c u r r e n t _ i d e n t i c a l _ c a l l s _ d e d u p l i c a t e d 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ d i f f e r e n t _ a r g s _ n o t _ d e d u p l i c a t e d 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ s e q u e n t i a l _ c a l l s _ n o t _ d e d u p l i c a t e d 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ e r r o r _ p r o p a g a t e d _ t o _ a l l _ c a l l e r s 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ c u s t o m _ k e y _ f n _ c o a l e s c e s _ b y _ r e s o u r c e _ t y p e 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ n o n e _ k e y _ f n _ o p t s _ o u t _ o f _ d e d u p l i c a t i o n 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ d e d u p l i c a t i o n _ b e n c h m a r k 
 
 t e s t s / t e s t _ d e d u p l i c a t i o n . p y : : t e s t _ d e d u p l i c a t i o n _ b e n c h m a r k 
 
     C : \ U s e r s \ A r y a n   S h a r m a \ D e s k t o p \ s m o o t h - a p i \ p a c k a g e s \ s m o o t h - a p i - p y \ s m o o t h _ a p i \ _ _ i n i t _ _ . p y : 7 0 :   D e p r e c a t i o n W a r n i n g :   ' a s y n c i o . i s c o r o u t i n e f u n c t i o n '   i s   d e p r e c a t e d   a n d   s l a t e d   f o r   r e m o v a l   i n   P y t h o n   3 . 1 6 ;   u s e   i n s p e c t . i s c o r o u t i n e f u n c t i o n ( )   i n s t e a d 
 
         i f   a s y n c i o . i s c o r o u t i n e f u n c t i o n ( f n ) : 
 
 
 
 - -   D o c s :   h t t p s : / / d o c s . p y t e s t . o r g / e n / s t a b l e / h o w - t o / c a p t u r e - w a r n i n g s . h t m l 
 
 = = = = = = = = = = = = = = = = = = = = = = = = = = =   s h o r t   t e s t   s u m m a r y   i n f o   = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 E R R O R   t e s t s / t e s t _ c o n c u r r e n c y . p y : : t e s t _ a s y n c _ w r a p p e r _ c o n c u r r e n c y   -   r e q u e s t s . e x . . . 
 
 E R R O R   t e s t s / t e s t _ i s o l a t i o n . p y : : t e s t _ d e c o r a t o r _ i s o l a t i o n _ a n d _ r u n t i m e _ o v e r r i d e 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ r e t r i e s _ o n _ 5 0 0 _ a n d _ e v e n t u a l l y _ s u c c e e d s 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ r e t r y _ r e s p e c t s _ r e t r y _ o n _ c o d e s   -   r e q u e s t s . . . 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ c i r c u i t _ t r i p s _ a n d _ r e t u r n s _ f a l l b a c k   -   r e q . . . 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ c i r c u i t _ o p e n _ r a i s e s _ r u n t i m e _ e r r o r _ w i t h o u t _ f a l l b a c k 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ c i r c u i t _ r e c o v e r s _ a f t e r _ c o o l d o w n   -   r e q u e s . . . 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ d e f a u l t _ b e h a v i o r   -   . . . 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ f a l l b a c k _ a n d _ s t d e r r 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ a s y n c _ f a l l b a c k _ a n d _ s t d e r r 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ c u s t o m _ f a l l b a c k   -   r . . . 
 
 E R R O R   t e s t s / t e s t _ r e s i l i e n c e . p y : : t e s t _ p y t h o n _ n o n _ r e t r y a b l e _ c u s t o m _ c a l l b a c k   -   r . . . 
 
 = = = = = = = = = = = = = = = = =   1 1   p a s s e d ,   9   w a r n i n g s ,   1 2   e r r o r s   i n   5 1 . 9 0 s   = = = = = = = = = = = = = = = = = = 
 
 