Browse Source

SmartCookie requires dict keys to be strings, not unicode

Matt Robenolt 10 years ago
parent
commit
d5be3d151a
1 changed files with 15 additions and 4 deletions
  1. 15 4
      src/sentry/interfaces/http.py

+ 15 - 4
src/sentry/interfaces/http.py

@@ -27,6 +27,13 @@ def format_headers(value):
     )
 
 
+def utf8_dict(value):
+    return dict(
+        (k.encode('utf8'), v)
+        for k, v in value.iteritems()
+    )
+
+
 class Http(Interface):
     """
     The Request information is stored in the Http interface. Two arguments
@@ -185,10 +192,14 @@ class Http(Interface):
     def to_curl(self):
         method = self.method.upper()
         if self.cookies:
-            cookies = SmartCookie(self.cookies)
-            # The Cookie header is already yanked out of the headers dict
-            # inside `to_python` so we can just safely re-set it.
-            self.headers['Cookie'] = ';'.join(c.output(attrs=[], header='') for c in cookies.values()).strip()
+            try:
+                cookies = SmartCookie(utf8_dict(self.cookies))
+            except Exception:
+                pass
+            else:
+                # The Cookie header is already yanked out of the headers dict
+                # inside `to_python` so we can just safely re-set it.
+                self.headers['Cookie'] = ';'.join(c.output(attrs=[], header='') for c in cookies.values()).strip()
         bits = []
         if method != 'GET':
             bits.append('-X' + method)