コード例 #1
0
 def patch(self, path: str, fields: Dict = None) -> bool:
     if not self.use_faster_than:
         encoded_body = json.dumps(fields)
         r = self.http.request(
             "PATCH", API_EP + path, headers=self.headers, body=encoded_body
         )
         if r.status == 200:
             return True
         else:
             print(f"Request <{path}> failed: {r.status}\nr.data= {r.data}")
             for k, v in fields.items():
                 print(f" :( {k}: {v}")
             return False
     else:
         result = requests.post(API_EP + path, json.dumps(fields))
         print(result)
         raise Exception("Sorry, faster-than-request post is not supported")
コード例 #2
0
import faster_than_requests as requests

with open(__file__) as f:
    print(requests.post("http://httpbin.org/post", f.read()))
コード例 #3
0
import faster_than_requests as requests

requests.init_client()

print(requests.get("http://httpbin.org/get"))  # HTTP GET.

print(
    requests.post("http://httpbin.org/post",
                  """{"foo": "bar", "baz": true}"""))  # HTTP POST.

print(requests.put("http://httpbin.org/put",
                   """{"foo": "bar", "baz": true}"""))  # HTTP PUT.

print(requests.delete("http://httpbin.org/delete"))  # HTTP DELETE.

print(
    requests.patch("http://httpbin.org/patch",
                   """{"foo": "bar", "baz": true}"""))  # HTTP PATCH.

print(requests.get2str(
    "http://httpbin.org/get"))  # HTTP GET body only to string response.

print(requests.get2dict(
    "http://httpbin.org/get"))  # HTTP GET body only to dictionary response.

print(requests.get2json(
    "http://httpbin.org/get"))  # HTTP GET body only to JSON response.

print(
    requests.post2str("http://httpbin.org/post",
                      """{"foo": "bar", "baz": true}""")
コード例 #4
0
 def test_post(self):
     self.assertIsInstance(
         faster_than_requests.post("http://httpbin.org/post",
                                   """{"foo": "bar", "baz": true}"""), dict)
コード例 #5
0
ファイル: bug126.py プロジェクト: nthon/faster-than-requests
import faster_than_requests

print(
  faster_than_requests.post(
    url          = "http://httpbin.org/post",
    body         = "{}",
    http_headers = [("Content-type", "application/json")])
)
コード例 #6
0
import faster_than_requests as requests

print( requests.post("http://httpbin.org/post", "", [("multi", "part"), ("key", "value")]) )

print( requests.post2str("http://httpbin.org/post",  "", [("multi", "part"), ("key", "value")]) )

print( requests.post2dict("http://httpbin.org/post", "", [("multi", "part"), ("key", "value")]) )

print( requests.post2json("http://httpbin.org/post", "", [("multi", "part"), ("key", "value")]) )