Closed emaheuxPEREN closed 2 months ago
Alternatively for another pcapng I get the following related error:
---------------------------------------------------------------------------
Error Traceback (most recent call last)
Cell In[2], line 17
15 traffic.parse_traffic()
16 # Save the HAR file
---> 17 traffic.save_har(Path(DIR / 'traffic.har'))
File /donnees/emaheux/repos/sdk-analysis/pcapng-utils/pcapng_utils/tshark/traffic.py:141, in NetworkTrafficDump.save_har(self, output_file)
135 """
136 Save the network traffic data in HAR format to a file.
137
138 :param output_file: the file to save the HAR data to
139 """
140 with output_file.open('w') as _of:
--> 141 json.dump(self.to_har(), _of, indent=2)
File /donnees/emaheux/repos/sdk-analysis/pcapng-utils/pcapng_utils/tshark/traffic.py:117, in NetworkTrafficDump.to_har(self)
115 entries = []
116 if self.http_traffic:
--> 117 entries.extend(self.http_traffic.get_har_entries())
118 if self.http2_traffic:
119 entries.extend(self.http2_traffic.get_har_entries())
File /donnees/emaheux/repos/sdk-analysis/pcapng-utils/pcapng_utils/tshark/protocols/http1.py:304, in HttpTraffic.get_har_entries(self)
302 entries = []
303 for http_conversation in self.conversations:
--> 304 entries.append(http_conversation.to_har())
305 return entries
File /donnees/emaheux/repos/sdk-analysis/pcapng-utils/pcapng_utils/tshark/protocols/http1.py:234, in HttpConversation.to_har(self)
219 def to_har(self):
220 """
221 Convert the HTTP conversation to HTTP Archive (HAR) format.
222 :return: the HTTP conversation (request and response) in HAR format
223 """
224 return {
225 'startedDateTime': self.request.started_date,
226 'timestamp': float(self.request.packet.get('frame').get('frame.time_epoch')),
227 'time': 0,
228 'timings': {
229 'send': self.request.sending_duration,
230 'wait': self.waiting_duration,
231 'receive': self.response.receiving_duration
232 },
233 'cache': {},
--> 234 'request': self.request.to_har(),
235 'response': self.response.to_har()
236 }
File /donnees/emaheux/repos/sdk-analysis/pcapng-utils/pcapng_utils/tshark/protocols/http1.py:103, in HttpRequest.to_har(self)
89 def to_har(self):
90 """
91 Convert the HTTP request to HTTP Archive (HAR) format.
92 :return: the HTTP request in HAR format
93 """
94 return {
95 'startedDateTime': self.started_date,
96 'method': self.method,
97 'url': self.uri,
98 'httpVersion': 'HTTP/1.1',
99 'headers': self.headers,
100 'queryString': [],
101 'cookies': [],
102 'headersSize': self.header_length,
--> 103 'bodySize': self.content_length,
104 'postData': {
105 'mimeType': self.content_type,
106 'base64': self.base64_content,
107 'text': self.decoded_content
108 }
109 }
File /donnees/emaheux/repos/sdk-analysis/pcapng-utils/pcapng_utils/tshark/protocols/http1.py:137, in HttpRequest.content_length(self)
135 @property
136 def content_length(self):
--> 137 return len(base64.b64decode(self.base64_content))
File ~/.pyenv/versions/3.11.9/lib/python3.11/base64.py:88, in b64decode(s, altchars, validate)
86 assert len(altchars) == 2, repr(altchars)
87 s = s.translate(bytes.maketrans(altchars, b'+/'))
---> 88 return binascii.a2b_base64(s, strict_mode=validate)
Error: Invalid base64-encoded string: number of data characters (97) cannot be 1 more than a multiple of 4
I tried to export my pcapng to HAR but got an
Incorrect padding
error frombinascii.a2b_base64
function. Here's the full traceback; I also join the input pcapng I used.My env: