Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import socket
  2. import json
  3.  
  4. DB_IP = '127.0.0.1'
  5. DB_PORT = 5984
  6.  
  7. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8.  
  9. sock.connect((DB_IP, DB_PORT))
  10.  
  11. db_name = 'temperatures'
  12. doc_id = 'today'
  13.  
  14. request = "PUT /" + db_name + "/" + doc_id + " HTTP/1.1n"
  15. request += "Content-Type: application/jsonnn"
  16. request += json.dumps({'min_t': 10, 'max_t': 20})
  17.  
  18. sock.sendall(request)
  19.  
  20. result = sock.recv(4096)
  21.  
  22. print result
  23.  
  24. HTTP/1.1 400 Bad Request
  25. Server: CouchDB/1.6.1 (Erlang OTP/19)
  26. Date: Mon, 27 Mar 2017 20:07:04 GMT
  27. Content-Type: text/plain; charset=utf-8
  28. Content-Length: 48
  29. Cache-Control: must-revalidate
  30.  
  31. [debug] [<0.575.0>] 'PUT' /temperatures/today {1,1} from "127.0.0.1"
  32. Headers: [{'Content-Type',"application/json"}]
  33. [debug] [<0.575.0>] OAuth Params: []
  34. [error] [<0.575.0>] attempted upload of invalid JSON (set log_level to debug to log it)
  35. [debug] [<0.575.0>] Invalid JSON: undefined
  36. [info] [<0.575.0>] 127.0.0.1 - - PUT /temperatures/today 400
  37. [debug] [<0.575.0>] httpd 400 error response:
  38. {"error":"bad_request","reason":"invalid_json"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement