Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning in python 3.12 when initial hello message being sent to TAK server (taky) #75

Open
inteq opened this issue Aug 15, 2024 · 0 comments

Comments

@inteq
Copy link

inteq commented Aug 15, 2024

When I try to send messages to my TAK server (taky in a local environment), I see the following deprecation warning exception being thrown during the generation of the hello event cot message:
python3.12/site-packages/pytak/functions.py", line 233, in gen_cot\n b"\\n".join([pytak.DEFAULT_XML_DECLARATION, ET.tostring(cot)]) if cot else None\n ^^^\nDeprecationWarning: Testing an element\'s truth value will raise an exception in future versions. Use specific \'len(elem)\' or \'elem is not None\' test instead.'} {'error': "Testing an element's truth value will raise an exception in future versions. Use specific 'len(elem)' or 'elem is not None' test instead."

In my local environment, I was able to resolve this by doing the following (this could definitely be cleaner):

 diff --git a/pytak/functions.py b/pytak/functions.py
index 9b98a91..fdd9e5c 100644
--- a/pytak/functions.py
+++ b/pytak/functions.py
@@ -221,10 +221,13 @@ def gen_cot(
 ) -> Optional[bytes]:
     """Generate a minimum CoT Event as an XML string [gen_cot_xml() wrapper]."""
     cot: Optional[ET.Element] = gen_cot_xml(lat, lon, ce, hae, le, uid, stale, cot_type)
-    return (
-        b"\n".join([pytak.DEFAULT_XML_DECLARATION, ET.tostring(cot)]) if cot else None
-    )

+    if cot is not None:
+        cot = b"\n".join([pytak.DEFAULT_XML_DECLARATION, ET.tostring(cot)])
+   return cot

Environment Details:
Python version : 3.12
Pytak version: 7.0.1
Python version manager: pyenv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant