[2.0a1] python3-maas-client needs to send data as bytes()
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MAAS |
Fix Released
|
Critical
|
Jeffrey C Jones |
Bug Description
Testing bleeding edge python3-maas-client API 2.0 with Xenial and python3
The client from both ppa:maas/next and ppa:~maas-
MAASClient put and post (possibly others) do not properly encode request data as bytes() leading to TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str. No matter how I encode the data in the put call this remains true.
In my testing I am trying to update a dnsresource using the 2.0 API.
Traceback (most recent call last):
File "hooks/test.py", line 81, in <module>
test_maas()
File "hooks/test.py", line 75, in test_maas
dns.
File "hooks/test.py", line 41, in update_resource
ip_address)
File "/home/
resp = self.driver.
File "/home/
ip_
File "/home/
response = self.client.
File "/usr/lib/
url, method="PUT", headers=headers, data=body)
File "/usr/lib/
res = urllib.
File "/usr/lib/
return opener.open(url, data, timeout)
File "/usr/lib/
req = meth(req)
File "/usr/lib/
raise TypeError(msg)
TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str.
A quick and dirty fix (likely not the correct one):
--- /usr/lib/
+++ maas_client.py 2016-03-09 16:14:12.643817715 -0800
@@ -214,6 +214,7 @@
body, headers = encode_
else:
body, headers = encode_
+ body = bytes(body, encoding='utf-8')
return url, headers, body
Related branches
- Blake Rouse (community): Approve
-
Diff: 52 lines (+16/-1)2 files modifiedsrc/apiclient/maas_client.py (+4/-1)
src/apiclient/tests/test_maas_client.py (+12/-0)
Changed in maas: | |
milestone: | none → 2.0.0 |
importance: | Undecided → Critical |
summary: |
- python3-maas-client needs to send data as bytes() + [2.0a1] python3-maas-client needs to send data as bytes() |
Changed in maas: | |
status: | New → Triaged |
Changed in maas: | |
assignee: | nobody → Jeffrey C Jones (trapnine) |
Changed in maas: | |
status: | Triaged → In Progress |
Changed in maas: | |
status: | In Progress → Fix Committed |
Changed in maas: | |
status: | Fix Committed → Fix Released |