I am trying to send a post payload however I was returned an error, can advise?
tracking_id is the id that I am using.
url = "https://www.google-analytics.com/debug/mp/collect"
payload = {
"v": 1,
"tid": tracking_id,
"cid": 555,
"t": "event",
"ec": "download",
"ea": "file_download",
"el": data['file_name'],
"ev": 1,
"cd5": data['hash']
}
response = requests.post(url, data=payload)
print(response.text)
Error message
{
"validationMessages": [ {
"description": "Unable to parse Measurement Protocol JSON payload. invalid JSON in google.analytics.measurement.Measurement, near 1:1 (offset 0): unexpected character: 'v'; expected '{'",
"validationCode": "VALUE_INVALID"
} ]
}
I have installed allinone setup using packstack in a server. I have generated one windows server instance and it was working fine. The system was left idle and later it was rebooted. After reboot, I'm not able to see the keystone service. I'm not able to start keystone service as well. It says the unit is not found but earlier keystone service was working fine and there are no logs of keystone after reboot. I'm not able ot start nova-conductor and nova-scheduler services. I'm attaching the log files for reference. Can anyone please share a way ahead to eliminate the error.
Thanks in advance.
Nova-scheduler Log:
2021-12-28 14:02:36.568 44587 ERROR nova keystoneauth1.exceptions.connection.ConnectFailure: Unable to establish connection to http://172.26.6.238:5000/v3/auth/tokens: HTTPConnectionPool(host='172.26.6.238', port=5000): Max retries exceeded with url: /v3/auth/tokens (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5f470529e8>: Failed to establish a new connection: [Errno 111] ECONNREFUSED',))
2021-12-28 14:02:36.568 44587 ERROR nova
2021-12-28 14:02:38.790 44597 INFO oslo_service.periodic_task [-] Skipping periodic task _discover_hosts_in_cells because its interval is negative
2021-12-28 14:02:38.799 44597 WARNING keystoneauth.identity.generic.base [-] Failed to discover available identity versions when contacting http://172.26.6.238:5000/v3. Attempting to parse version from URL.: keystoneauth1.exceptions.connection.ConnectFailure: Unable to establish connection to http://172.26.6.238:5000/v3: HTTPConnectionPool(host='172.26.6.238', port=5000): Max retries exceeded with url: /v3 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f53f3575a20>: Failed to establish a new connection: [Errno 111] ECONNREFUSED',))
2021-12-28 14:02:38.803 44597 CRITICAL nova [-] Unhandled error: keystoneauth1.exceptions.connection.ConnectFailure: Unable to establish connection to http://172.26.6.238:5000/v3/auth/tokens: HTTPConnectionPool(host='172.26.6.238', port=5000): Max retries exceeded with url: /v3/auth/tokens (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f53f358e9e8>: Failed to establish a new connection: [Errno 111] ECONNREFUSED',))
2021-12-28 14:02:38.803 44597 ERROR nova Traceback (most recent call last):
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
2021-12-28 14:02:38.803 44597 ERROR nova (self._dns_host, self.port), self.timeout, **extra_kw)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
2021-12-28 14:02:38.803 44597 ERROR nova raise err
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
2021-12-28 14:02:38.803 44597 ERROR nova sock.connect(sa)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/eventlet/greenio/base.py", line 253, in connect
2021-12-28 14:02:38.803 44597 ERROR nova socket_checkerr(fd)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/eventlet/greenio/base.py", line 51, in socket_checkerr
2021-12-28 14:02:38.803 44597 ERROR nova raise socket.error(err, errno.errorcode[err])
2021-12-28 14:02:38.803 44597 ERROR nova ConnectionRefusedError: [Errno 111] ECONNREFUSED
2021-12-28 14:02:38.803 44597 ERROR nova
2021-12-28 14:02:38.803 44597 ERROR nova During handling of the above exception, another exception occurred:
2021-12-28 14:02:38.803 44597 ERROR nova
2021-12-28 14:02:38.803 44597 ERROR nova Traceback (most recent call last):
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
2021-12-28 14:02:38.803 44597 ERROR nova chunked=chunked)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
2021-12-28 14:02:38.803 44597 ERROR nova conn.request(method, url, **httplib_request_kw)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1254, in request
2021-12-28 14:02:38.803 44597 ERROR nova self._send_request(method, url, body, headers, encode_chunked)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1300, in _send_request
2021-12-28 14:02:38.803 44597 ERROR nova self.endheaders(body, encode_chunked=encode_chunked)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1249, in endheaders
2021-12-28 14:02:38.803 44597 ERROR nova self._send_output(message_body, encode_chunked=encode_chunked)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1036, in _send_output
2021-12-28 14:02:38.803 44597 ERROR nova self.send(msg)
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 974, in send
2021-12-28 14:02:38.803 44597 ERROR nova self.connect()
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect
2021-12-28 14:02:38.803 44597 ERROR nova conn = self._new_conn()
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
2021-12-28 14:02:38.803 44597 ERROR nova self, "Failed to establish a new connection: %s" % e)
2021-12-28 14:02:38.803 44597 ERROR nova urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f53f358e9e8>: Failed to establish a new connection: [Errno 111] ECONNREFUSED
2021-12-28 14:02:38.803 44597 ERROR nova
2021-12-28 14:02:38.803 44597 ERROR nova During handling of the above exception, another exception occurred:
2021-12-28 14:02:38.803 44597 ERROR nova
2021-12-28 14:02:38.803 44597 ERROR nova Traceback (most recent call last):
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
2021-12-28 14:02:38.803 44597 ERROR nova timeout=timeout
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
2021-12-28 14:02:38.803 44597 ERROR nova _stacktrace=sys.exc_info()[2])
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 399, in increment
2021-12-28 14:02:38.803 44597 ERROR nova raise MaxRetryError(_pool, url, error or ResponseError(cause))
2021-12-28 14:02:38.803 44597 ERROR nova urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='172.26.6.238', port=5000): Max retries exceeded with url: /v3/auth/tokens (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f53f358e9e8>: Failed to establish a new connection: [Errno 111] ECONNREFUSED',))
2021-12-28 14:02:38.803 44597 ERROR nova
2021-12-28 14:02:38.803 44597 ERROR nova During handling of the above exception, another exception occurred:
2021-12-28 14:02:38.803 44597 ERROR nova
2021-12-28 14:02:38.803 44597 ERROR nova Traceback (most recent call last):
2021-12-28 14:02:38.803 44597 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/session.py", line 1004, in _send_request
2021-12-28 14:02:38.803 44597 ERROR nova resp = self.session.request(method, url, **kwargs)
Nova-Conductor Log
2021-12-28 15:08:32.128 82721 ERROR nova ConnectionRefusedError: [Errno 111] ECONNREFUSED
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova During handling of the above exception, another exception occurred:
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova Traceback (most recent call last):
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
2021-12-28 15:08:32.128 82721 ERROR nova chunked=chunked)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
2021-12-28 15:08:32.128 82721 ERROR nova conn.request(method, url, **httplib_request_kw)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1254, in request
2021-12-28 15:08:32.128 82721 ERROR nova self._send_request(method, url, body, headers, encode_chunked)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1300, in _send_request
2021-12-28 15:08:32.128 82721 ERROR nova self.endheaders(body, encode_chunked=encode_chunked)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1249, in endheaders
2021-12-28 15:08:32.128 82721 ERROR nova self._send_output(message_body, encode_chunked=encode_chunked)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 1036, in _send_output
2021-12-28 15:08:32.128 82721 ERROR nova self.send(msg)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib64/python3.6/http/client.py", line 974, in send
2021-12-28 15:08:32.128 82721 ERROR nova self.connect()
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect
2021-12-28 15:08:32.128 82721 ERROR nova conn = self._new_conn()
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
2021-12-28 15:08:32.128 82721 ERROR nova self, "Failed to establish a new connection: %s" % e)
2021-12-28 15:08:32.128 82721 ERROR nova urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fc0e5be6978>: Failed to establish a new connection: [Errno 111] ECONNREFUSED
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova During handling of the above exception, another exception occurred:
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova Traceback (most recent call last):
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
2021-12-28 15:08:32.128 82721 ERROR nova timeout=timeout
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
2021-12-28 15:08:32.128 82721 ERROR nova _stacktrace=sys.exc_info()[2])
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 399, in increment
2021-12-28 15:08:32.128 82721 ERROR nova raise MaxRetryError(_pool, url, error or ResponseError(cause))
2021-12-28 15:08:32.128 82721 ERROR nova urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='172.26.6.238', port=5000): Max retries exceeded with url: /v3/auth/tokens (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc0e5be6978>: Failed to establish a new connection: [Errno 111] ECONNREFUSED',))
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova During handling of the above exception, another exception occurred:
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova Traceback (most recent call last):
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/session.py", line 1004, in _send_request
2021-12-28 15:08:32.128 82721 ERROR nova resp = self.session.request(method, url, **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
2021-12-28 15:08:32.128 82721 ERROR nova resp = self.send(prep, **send_kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
2021-12-28 15:08:32.128 82721 ERROR nova r = adapter.send(request, **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
2021-12-28 15:08:32.128 82721 ERROR nova raise ConnectionError(e, request=request)
2021-12-28 15:08:32.128 82721 ERROR nova requests.exceptions.ConnectionError: HTTPConnectionPool(host='172.26.6.238', port=5000): Max retries exceeded with url: /v3/auth/tokens (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc0e5be6978>: Failed to establish a new connection: [Errno 111] ECONNREFUSED',))
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova During handling of the above exception, another exception occurred:
2021-12-28 15:08:32.128 82721 ERROR nova
2021-12-28 15:08:32.128 82721 ERROR nova Traceback (most recent call last):
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/bin/nova-conductor", line 10, in
2021-12-28 15:08:32.128 82721 ERROR nova sys.exit(main())
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/cmd/conductor.py", line 44, in main
2021-12-28 15:08:32.128 82721 ERROR nova topic=rpcapi.RPC_TOPIC)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/service.py", line 270, in create
2021-12-28 15:08:32.128 82721 ERROR nova periodic_interval_max=periodic_interval_max)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/service.py", line 128, in init
2021-12-28 15:08:32.128 82721 ERROR nova self.manager = manager_class(host=self.host, *args, **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/conductor/manager.py", line 121, in init
2021-12-28 15:08:32.128 82721 ERROR nova self.compute_task_mgr = ComputeTaskManager()
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/conductor/manager.py", line 247, in init
2021-12-28 15:08:32.128 82721 ERROR nova self.report_client = report.SchedulerReportClient()
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/scheduler/client/report.py", line 186, in init
2021-12-28 15:08:32.128 82721 ERROR nova self._client = self._create_client()
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/scheduler/client/report.py", line 229, in _create_client
2021-12-28 15:08:32.128 82721 ERROR nova client = self._adapter or utils.get_sdk_adapter('placement')
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/nova/utils.py", line 1079, in get_sdk_adapter
2021-12-28 15:08:32.128 82721 ERROR nova return getattr(conn, service_type)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/openstack/service_description.py", line 93, in get
2021-12-28 15:08:32.128 82721 ERROR nova endpoint = proxy_mod.Proxy.get_endpoint(proxy)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/adapter.py", line 282, in get_endpoint
2021-12-28 15:08:32.128 82721 ERROR nova return self.session.get_endpoint(auth or self.auth, **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/session.py", line 1225, in get_endpoint
2021-12-28 15:08:32.128 82721 ERROR nova return auth.get_endpoint(self, **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/identity/base.py", line 380, in get_endpoint
2021-12-28 15:08:32.128 82721 ERROR nova allow_version_hack=allow_version_hack, **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/identity/base.py", line 271, in get_endpoint_data
2021-12-28 15:08:32.128 82721 ERROR nova service_catalog = self.get_access(session).service_catalog
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/identity/base.py", line 134, in get_access
2021-12-28 15:08:32.128 82721 ERROR nova self.auth_ref = self.get_auth_ref(session)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/identity/generic/base.py", line 208, in get_auth_ref
2021-12-28 15:08:32.128 82721 ERROR nova return self._plugin.get_auth_ref(session, **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/identity/v3/base.py", line 184, in get_auth_ref
2021-12-28 15:08:32.128 82721 ERROR nova authenticated=False, log=False, **rkwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/session.py", line 1131, in post
2021-12-28 15:08:32.128 82721 ERROR nova return self.request(url, 'POST', **kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/session.py", line 913, in request
2021-12-28 15:08:32.128 82721 ERROR nova resp = send(**kwargs)
2021-12-28 15:08:32.128 82721 ERROR nova File "/usr/lib/python3.6/site-packages/keystoneauth1/session.py", line 1020, in _send_request
2021-12-28 15:08:32.128 82721 ERROR nova raise exceptions.ConnectFailure(msg)
2021-12-28 15:08:32.128 82721 ERROR nova keystoneauth1.exceptions.connection.ConnectFailure: Unable to establish connection to http://172.26.6.238:5000/v3/auth/tokens: HTTPConnectionPool(host='172.26.6.238', port=5000): Max retries exceeded with url: /v3/auth/tokens (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc0e5be6978>: Failed to establish a new connection: [Errno 111] ECONNREFUSED',))
2021-12-28 15:08:32.128 82721 ERROR nova
The error messages in the logfile say that it cannot connect to http://172.26.6.238:5000/v3/auth/tokens. That will be your Keystone service.
You need to investigate why your Keystone service is not listening for connections.
I'm not able to start Keystone service as well.
Solve that problem first.
It says the unit is not found ...
Suspicious! Systemd unit files don't just spontaneously disappear. You need to figure out where they have gone.
import http.client, urllib.request, urllib.parse, urllib.error, base64
headers = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': '{subscription key}',
}
params = urllib.parse.urlencode({
# Request parameters
'returnFaceId': 'true',
'returnFaceLandmarks': 'false',
'returnFaceAttributes': '{string}',
'recognitionModel': 'recognition_01',
'returnRecognitionModel': 'false',
})
try:
conn =http.client.HTTPSConnection('southeastasia.api.cognitive.microsoft.com')
conn.request("POST", "/face/v1.0/detect?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
The above code is not working.
I gave correct 1key1 value
I am getting:
[Errno 11002] getaddrinfo failed
I am trying to make a PUT method (or POST) to DropBox api, but it doesent work, I get a GET instead?
import tornado.ioloop
import tornado.web
from tornado.httputil import HTTPHeaders
from tornado.httpclient import HTTPClient, HTTPRequest
url = "https://api-content.dropbox.com/1/files_put/sandbox/world.txt"
class MainHandler(tornado.web.RequestHandler):
def post(self):
headers = HTTPHeaders({'Authorization': 'Bearer TOKEN_FOR_DROPBOX'})
HTTPClient().fetch(
HTTPRequest(url, 'PUT', body="hello there", headers=headers))
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.current().start()
Update: using GET makes an error: HTTPError: HTTP 400: Bad Request
Here is a new code:
import tornado.ioloop
import tornado.web
from tornado.httpclient import HTTPClient, HTTPRequest
url = "https://api-content.dropbox.com/1/files_put/sandbox/wor.txt"
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.set_header('Authorization', 'Bearer DROPBOX_TOKEN')
self.set_header('Content-Type', 'text/plain')
HTTPClient().fetch(
HTTPRequest(url, 'PUT', body="hello there"))
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.current().start()
but get this error:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\tornado\web.py", line 1415, in _execute
result = yield result
File "C:\Python27\lib\site-packages\tornado\gen.py", line 870, in run
value = future.result()
File "C:\Python27\lib\site-packages\tornado\concurrent.py", line 215, in result
raise_exc_info(self._exc_info)
File "C:\Python27\lib\site-packages\tornado\gen.py", line 230, in wrapper
yielded = next(result)
File "C:\Users\Abdelouahab\Desktop\ttttt.py", line 14, in get
HTTPRequest(url, 'PUT', body="hello there"))
File "C:\Python27\lib\site-packages\tornado\httpclient.py", line 102, in fetch
self._async_client.fetch, request, **kwargs))
File "C:\Python27\lib\site-packages\tornado\ioloop.py", line 445, in run_sync
return future_cell[0].result()
File "C:\Python27\lib\site-packages\tornado\concurrent.py", line 215, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
HTTPError: HTTP 401: Unauthorized
ERROR:tornado.access:500 GET / (::1) 806.00ms
I tried using an HTTP request builder extension from Mozilla, and it worked, so I guess the problem is how to do it on Tornado?
Sorry, it seems that it missed the content-type
import tornado.ioloop
import tornado.web
from tornado.httputil import HTTPHeaders
from tornado.httpclient import HTTPClient, HTTPRequest
from tornado.gen import coroutine
url = "https://api-content.dropbox.com/1/files_put/sandbox/wor.txt"
class MainHandler(tornado.web.RequestHandler):
#coroutine
def get(self):
headers = HTTPHeaders({'Authorization': 'Bearer DROPBOX_TOKEN', 'Content-Type':'text/plain'})
HTTPClient().fetch(
HTTPRequest(url, 'PUT', body="hello there", headers=headers))
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.current().start()
I need to modify some Coffeescript to include a timeout for HTTP requests. Below is the code. I have tried adding a 'timeout' property to the requestOptions dictionary but no luck!
Below is the code which you can also find on Github (https://github.com/pcrawfor/iap_verifier/blob/master/src/iap_verifier.coffee#L144)
###
verifyReceipt
Verifies an In App Purchase receipt string against Apple's servers
params:
receipt - the receipt string
isBase64 - Is the receipt already encoded in base64? Optional, defaults to false.
cb - callback function that will return the status code and results for the verification call
###
verifyReceipt: (receipt, isBase64, cb) ->
if cb is undefined
cb = isBase64
isBase64 = false
data =
'receipt-data': ""
#verifyWithRetry(data, receipt, isBase64, cb)
###
verifyWithRetry
Verify with retry will automatically call the Apple Sandbox verification server in the event that a 21007 error code is returned.
This error code is an indication that the app may be receiving app store review requests.
###
verifyWithRetry: (receiptData, receipt, isBase64, cb) ->
encoded = null
if isBase64
encoded = receipt
else
buffer = new Buffer(receipt)
encoded = buffer.toString('base64')
receiptData['receipt-data'] = encoded
#verify receiptData, #requestOptions(), (valid, msg, data) =>
# on a 21007 error retry the request for the Sandbox environment (if the current environment is Production)
if (21007 == data.status) && (#productionHost == #host)
# retry...
if #debug then console.log("Retry on Sandbox")
options = #requestOptions()
options.host = #sandboxHost
#verify receiptData, options, (valid, msg, data) ->
if #debug then console.log("STATUS #{data.status}")
cb(valid, msg, data)
else
if #debug then console.log "else"
cb(valid, msg, data)
###
verify the receipt data
###
verify: (data, options, cb) ->
if #debug then console.log("verify!")
post_data = JSON.stringify(data)
options.headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
request = https.request options, (response) =>
if #debug then console.log("statusCode: #{response.statusCode}")
if #debug then console.log("headers: #{response.headers}")
apple_response_arr = []
response.on 'data', (data) =>
if #debug then console.log("data #{data}")
if response.statusCode != 200
if #debug then console.log("error: " + data)
return cb(false, "error", null)
apple_response_arr.push(data)
response.on 'end', () =>
totalData = apple_response_arr.join('')
if #debug then console.log "end: apple response: #{totalData}"
responseData = JSON.parse(totalData)
#processStatus(responseData, cb)
response.on 'timeout', () =>
console.log('timeout')
return cb(false, "error", null)
request.write(post_data)
request.end()
request.on 'error', (err) ->
if #debug then console.log("In App purchase verification error: #{err}")
processStatus: (data, cb) ->
# evaluate status code and take an action, write any new receipts to the database
if #debug then console.log("Process status #{data.status}")
#todo: check status code and react appropriately
response = #responseCodes[data.status]
# Try not to blow up if we encounter an unknown/unexepected status code
unless response
response =
valid: false
error: true
message: "Unknown status code: " + data.status
cb(response.valid, response.message, data)
requestOptions: ->
options =
host: #host
port: #port
path: #path
method: #method
# timeout: 100 // didn't work :(
module.exports = IAPVerifier