@@ -129,6 +129,7 @@ def __init__(self,
129
129
# __conn being created __del__() can detect the condition and handle it
130
130
# correctly.
131
131
self .__conn = None
132
+ authpair = None
132
133
133
134
if service_url is None :
134
135
# Figure out the path to the bitcoin.conf file
@@ -186,8 +187,12 @@ def __init__(self,
186
187
else :
187
188
port = self .__url .port
188
189
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 )
191
196
192
197
self .__conn = httplib .HTTPConnection (self .__url .hostname , port = port ,
193
198
timeout = timeout )
@@ -200,11 +205,17 @@ def _call(self, service_name, *args):
200
205
'method' : service_name ,
201
206
'params' : args ,
202
207
'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 )
208
219
209
220
response = self ._get_response ()
210
221
if response ['error' ] is not None :
@@ -218,12 +229,17 @@ def _call(self, service_name, *args):
218
229
219
230
def _batch (self , rpc_call_list ):
220
231
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' })
226
232
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 )
227
243
return self ._get_response ()
228
244
229
245
def _get_response (self ):
0 commit comments