11from dataclasses import dataclass
2+ from io import StringIO
23from typing import Dict , Any , Optional , BinaryIO
34
5+ import requests
6+
47from scaleway_core .bridge import Zone
58from scaleway_core .profile import ProfileDefaults
69from scaleway_core .utils import validate_path_param
@@ -47,7 +50,7 @@ class SetServerUserDataRequest:
4750 Key defines the user data key to set
4851 """
4952
50- content : BinaryIO
53+ content : str
5154 """
5255 Content defines the data to set
5356 """
@@ -104,11 +107,11 @@ def get_server_user_data(self, server_id: str, key: str, zone: Optional[Zone] =
104107 self .client ,
105108 ),
106109 )
107-
110+ print ( "res from api: " , res . text )
108111 self ._throw_on_error (res )
109112 return res .json ()
110113
111- def set_server_user_data (self , server_id : str , key : str , content : BinaryIO , zone : Optional [Zone ] = None ):
114+ def set_server_user_data (self , server_id : str , key : str , content : StringIO , zone : Optional [Zone ] = None ):
112115 """
113116 Sets the content of a user data on a server for the given key.
114117 :param zone: Zone to target. If none is passed, it will use the default zone from the config.
@@ -119,23 +122,24 @@ def set_server_user_data(self, server_id: str, key: str, content: BinaryIO, zone
119122 """
120123 param_zone = validate_path_param ("zone" , zone or self .client .default_zone )
121124 param_server_id = validate_path_param ("server_id" , server_id )
122-
125+ body = content .read ()
126+ headers = {
127+ 'Content-Type' : 'text/plain' ,
128+ }
123129 res = self ._request (
124130 "PATCH" ,
125131 f"/instance/v1/zones/{ param_zone } /servers/{ param_server_id } /user_data/{ key } " ,
126- body = marshal_SetServerUserDataRequest (
127- SetServerUserDataRequest (
128- zone = zone ,
129- server_id = server_id ,
130- key = key ,
131- content = content ,
132- ),
133- self .client ,
134- ),
132+ body = body ,
133+ headers = headers ,
135134 )
135+ try :
136+ response_text = res .text # Expect plain text
137+ except requests .exceptions .JSONDecodeError :
138+ print (f"Failed to decode JSON. Response content: { res .text } " )
139+ response_text = None
136140
137141 self ._throw_on_error (res )
138- return res . json ()
142+ return response_text
139143
140144
141145
0 commit comments