-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
Brief description
The "Test chunked with gzip" test fails with
File "/home/vagrant/scapy/scapy/layers/http.py", line 437, in self_build
val = datetime.datetime.utcnow().strftime(
^^^^^^^^^^^^^^^^^^^^^^^^^^
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
Scapy version
Python version
Python 3.12.4
Operating system
Linux version 6.9.7-200.fc40.x86_64
Additional environment information
No response
How to reproduce
python3 -Werror -m scapy.tools.UTscapy -t test/scapy/layers/http.uts
Actual result
###(011)=[failed] Test chunked with gzip
###(011)=[failed] Test chunked with gzip
^[[34m^[[1m>>> ^[[0mconf.contribs["http"]["auto_compression"] = False
^[[34m^[[1m>>> ^[[0mconf.contribs["http"]["auto_chunk"] = False
^[[34m^[[1m>>> ^[[0mz = b'\x1f\x8b\x08\x00S\\-_\x02\xff\xb3\xc9(\xc9\xcd\xb1\xcb\xcd)\xb0\xd1\x07\xb3\x00\xe6\xedpt\x10\x00\x00\x00'
^[[34m^[[1m>>> ^[[0ma = IP(dst="1.1.1.1", src="2.2.2.2")/TCP(seq=1)/HTTP()/HTTPResponse(Content_Encoding="gzip", Transfer_Encoding="chunked")/(b"5\r\n" + z[:5] + b"\r\n")
^[[34m^[[1m>>> ^[[0mb = IP(dst="1.1.1.1", src="2.2.2.2")/TCP(seq=len(a[TCP].payload)+1)/HTTP()/(hex(len(z[5:])).encode()[2:] + b"\r\n" + z[5:] + b"\r\n0\r\n\r\n")
Traceback (most recent call last):
File "<input>", line 2, in <module>
File "/home/vagrant/scapy/scapy/packet.py", line 646, in __len__
return len(self.__bytes__())
^^^^^^^^^^^^^^^^
File "/home/vagrant/scapy/scapy/packet.py", line 605, in __bytes__
return self.build()
^^^^^^^^^^^^
File "/home/vagrant/scapy/scapy/packet.py", line 764, in build
p = self.do_build()
^^^^^^^^^^^^^^^
File "/home/vagrant/scapy/scapy/packet.py", line 747, in do_build
pay = self.do_build_payload()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vagrant/scapy/scapy/packet.py", line 733, in do_build_payload
return self.payload.do_build()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vagrant/scapy/scapy/packet.py", line 744, in do_build
pkt = self.self_build()
^^^^^^^^^^^^^^^^^
File "/home/vagrant/scapy/scapy/layers/http.py", line 437, in self_build
val = datetime.datetime.utcnow().strftime(
^^^^^^^^^^^^^^^^^^^^^^^^^^
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
Expected result
The test should pass. I fixed the http test locally with
diff --git a/scapy/layers/http.py b/scapy/layers/http.py
index 2e211840..617e516a 100644
--- a/scapy/layers/http.py
+++ b/scapy/layers/http.py
@@ -434,7 +434,7 @@ class _HTTPContent(Packet):
# Add Content-Length anyways
val = str(len(self.payload or b""))
elif f.name == "Date" and isinstance(self, HTTPResponse):
- val = datetime.datetime.utcnow().strftime(
+ val = datetime.datetime.now(datetime.timezone.utc).strftime(
'%a, %d %b %Y %H:%M:%S GMT'
)
else:
but there are other places where utcnow
and utcfromtimestamp
are used
scapy/__init__.py: d = datetime.datetime.utcfromtimestamp(int(tstamp))
scapy/__init__.py: d = datetime.datetime.utcfromtimestamp(os.path.getmtime(__file__))
scapy/layers/kerberos.py: now_time = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc)
scapy/layers/kerberos.py: now_time = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc)
scapy/layers/kerberos.py: now_time = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc)
scapy/layers/kerberos.py: now_time = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc)
scapy/layers/kerberos.py: now_time = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc)
scapy/layers/kerberos.py: now_time = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc)
scapy/modules/ticketer.py: now_time = datetime.utcnow().replace(microsecond=0, tzinfo=timezone.utc)
test/regression.uts:mtime = datetime.utcfromtimestamp(os.path.getmtime(scapy.__file__))
test/scapy/layers/kerberos.uts:date_mock.utcnow.return_value = datetime(2024, 3, 5, 16, 52, 55, 424801)
They should probably be replaced too but I haven't gotten round to it yet.
Related resources
utcnow
and utcfromtimestamp
were deprecated in python/cpython#103857
Metadata
Metadata
Assignees
Labels
No labels