@@ -129,6 +129,7 @@ def __init__(self,
129129 # __conn being created __del__() can detect the condition and handle it
130130 # correctly.
131131 self .__conn = None
132+ authpair = None
132133
133134 if service_url is None :
134135 # Figure out the path to the bitcoin.conf file
@@ -186,8 +187,12 @@ def __init__(self,
186187 else :
187188 port = self .__url .port
188189 self .__id_count = 0
189- authpair = authpair .encode ('utf8' )
190- self .__auth_header = b"Basic " + base64 .b64encode (authpair )
190+
191+ if authpair is None :
192+ self .__auth_header = None
193+ else :
194+ authpair = authpair .encode ('utf8' )
195+ self .__auth_header = b"Basic " + base64 .b64encode (authpair )
191196
192197 self .__conn = httplib .HTTPConnection (self .__url .hostname , port = port ,
193198 timeout = timeout )
@@ -200,11 +205,17 @@ def _call(self, service_name, *args):
200205 'method' : service_name ,
201206 'params' : args ,
202207 'id' : self .__id_count })
203- self .__conn .request ('POST' , self .__url .path , postdata ,
204- {'Host' : self .__url .hostname ,
205- 'User-Agent' : DEFAULT_USER_AGENT ,
206- 'Authorization' : self .__auth_header ,
207- 'Content-type' : 'application/json' })
208+
209+ headers = {
210+ 'Host' : self .__url .hostname ,
211+ 'User-Agent' : DEFAULT_USER_AGENT ,
212+ 'Content-type' : 'application/json' ,
213+ }
214+
215+ if self .__auth_header is not None :
216+ headers ['Authorization' ] = self .__auth_header
217+
218+ self .__conn .request ('POST' , self .__url .path , postdata , headers )
208219
209220 response = self ._get_response ()
210221 if response ['error' ] is not None :
@@ -218,12 +229,17 @@ def _call(self, service_name, *args):
218229
219230 def _batch (self , rpc_call_list ):
220231 postdata = json .dumps (list (rpc_call_list ))
221- self .__conn .request ('POST' , self .__url .path , postdata ,
222- {'Host' : self .__url .hostname ,
223- 'User-Agent' : DEFAULT_USER_AGENT ,
224- 'Authorization' : self .__auth_header ,
225- 'Content-type' : 'application/json' })
226232
233+ headers = {
234+ 'Host' : self .__url .hostname ,
235+ 'User-Agent' : DEFAULT_USER_AGENT ,
236+ 'Content-type' : 'application/json' ,
237+ }
238+
239+ if self .__auth_header is not None :
240+ headers ['Authorization' ] = self .__auth_header
241+
242+ self .__conn .request ('POST' , self .__url .path , postdata , headers )
227243 return self ._get_response ()
228244
229245 def _get_response (self ):
0 commit comments