Skip to content

Commit 4e7369c

Browse files
joaolcorreiaclaude
andcommitted
Fix Python 3 compatibility in API enrichment test servers
- Replace deprecated headers.getheader() with headers.get() - Fix base64.b64encode() to work with bytes in Python 3 - Replace base64.decodestring() with base64.b64decode() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent dbb4192 commit 4e7369c

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

integration-tests/common-fs2/api-enrichment-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def do_POST(self):
3838
self.write_body(response)
3939
else:
4040
self.do_AUTHHEAD()
41-
self.write_body(self.headers.getheader('Authorization'))
41+
self.write_body(self.headers.get('Authorization') or '')
4242
self.write_body('not authenticated')
4343

4444
def do_GET(self):

integration-tests/common/api-enrichment-test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def do_POST(self):
2020
''' Present frontpage with user authentication. '''
2121
self.post_request_counter += 1
2222
self.protocol_version='HTTP/1.1'
23-
auth = self.headers.getheader('Authorization')
23+
auth = self.headers.get('Authorization')
24+
expected_auth = 'Basic ' + base64.b64encode(b'snowplower:supersecret').decode('utf-8')
2425
if self.path.startswith("/guest"):
2526
self.send_response(200)
2627
response = self.generate_response("POST")
@@ -30,15 +31,15 @@ def do_POST(self):
3031
elif auth is None:
3132
self.do_AUTHHEAD()
3233
self.write_body('no auth header received')
33-
elif auth == 'Basic ' + base64.b64encode('snowplower:supersecret'):
34+
elif auth == expected_auth:
3435
response = self.generate_response("POST", auth)
3536
self.send_response(200)
3637
self.send_header('Content-length', len(response))
3738
self.end_headers()
3839
self.write_body(response)
3940
else:
4041
self.do_AUTHHEAD()
41-
self.write_body(self.headers.getheader('Authorization'))
42+
self.write_body(self.headers.get('Authorization') or '')
4243
self.write_body('not authenticated')
4344

4445
def do_GET(self):
@@ -57,7 +58,7 @@ def do_GET(self):
5758

5859
def generate_response(self, method, auth=None):
5960
if auth is not None:
60-
userpass = base64.decodestring(auth[6:])
61+
userpass = base64.b64decode(auth[6:]).decode('utf-8')
6162
response = {
6263
"rootNull": None,
6364
"data": {

0 commit comments

Comments
 (0)