I'm doing a POST request to an API, the code looks like this:
#gen.coroutine
def call():
...
response = yield AsyncHTTPClient().fetch(
HTTPRequest(
url='https://api.mywebsite.com/v1/users',
headers=headers,
method='POST',
body=json.dumps(body),
validate_cert=False
)
)
print response, response.body
if __name__ == "__main__":
tornado.ioloop.IOLoop.current().run_sync(call)
The server responds first time with 201 Created and the second time with 200 OK.
But for that code I get this error for the first time. The second time works
Traceback (most recent call last):
File "t.py", line 49, in <module>
tornado.ioloop.IOLoop.current().run_sync(call)
File "/usr/lib/python2.7/dist-packages/tornado/ioloop.py", line 389, in run_sync
return future_cell[0].result()
File "/usr/lib/python2.7/dist-packages/tornado/concurrent.py", line 129, in result
raise_exc_info(self.__exc_info)
File "/usr/lib/python2.7/dist-packages/tornado/stack_context.py", line 302, in wrapped
ret = fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 574, in inner
self.set_result(key, result)
File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 500, in set_result
self.run()
File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 529, in run
yielded = self.gen.throw(*exc_info)
File "t.py", line 43, in call
validate_cert=False
File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 520, in run
next = self.yield_point.get_result()
File "/usr/lib/python2.7/dist-packages/tornado/gen.py", line 409, in get_result
return self.runner.pop_result(self.key).result()
File "/usr/lib/python2.7/dist-packages/tornado/concurrent.py", line 131, in result
return super(TracebackFuture, self).result(timeout=timeout)
File "/usr/lib/python2.7/dist-packages/concurrent/futures/_base.py", line 401, in result
return self.__get_result()
File "/usr/lib/python2.7/dist-packages/concurrent/futures/_base.py", line 360, in __get_result
raise self._exception
AssertionError
Looks like you are using sync function HTTPRequest in future
from tornado.httpclient import AsyncHTTPClient
from tornado.httpclient import HTTPResponse
def call():
response = None
http_client = AsyncHTTPClient()
try:
body = json.dumps(body)
response: HTTPResponse = yield http_client.fetch('https://api.mywebsite.com/v1/users', method='POST', body=str(body), headers=headers, request_timeout=5)
except Exception as e:
print('get_request error:{0}'.format(e))
Related
I am trying to create a webservice to update a wallet pass using apns push notifications. I am using httpx for this as it can use http/2. I have the following test code for this:
import httpx
import ssl
import asyncio
async def send_push():
context = ssl.create_default_context()
context.load_verify_locations(cafile = "/Users/valley/Desktop/External_Finder/Learning_Centers_Development/Arcade-Pass/certs/passcertificate.pem")
payload = {
"aps" : ""
}
async with httpx.AsyncClient(http2 = True, cert = "/Users/valley/Desktop/External_Finder/Learning_Centers_Development/Arcade-Pass/certs/ArcadePassCertKey.pem") as client:
r = await client.post("https://api.sandbox.push.apple.com:2197/3/device/4c526af3e9cd29cc0c6f8954de5f68fd1d00348696fe4a984581e35f19fe1ddf", data = payload)
print(r.http_version)
print(r.text)
asyncio.run(send_push())
When I try to run this, I am getting the following traceback and error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
yield
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 253, in handle_async_request
raise exc
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 237, in handle_async_request
response = await connection.handle_async_request(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/connection.py", line 90, in handle_async_request
return await self._connection.handle_async_request(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/http2.py", line 146, in handle_async_request
raise exc
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/http2.py", line 114, in handle_async_request
status, headers = await self._receive_response(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/http2.py", line 231, in _receive_response
event = await self._receive_stream_event(request, stream_id)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/http2.py", line 262, in _receive_stream_event
await self._receive_events(request, stream_id)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpcore/_async/http2.py", line 291, in _receive_events
raise RemoteProtocolError(event)
httpcore.RemoteProtocolError: <ConnectionTerminated error_code:ErrorCodes.NO_ERROR, last_stream_id:0, additional_data:7b22726561736f6e223a22426164436572746966>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test_push_notifications.py", line 24, in <module>
asyncio.run(send_push())
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py", line 608, in run_until_complete
return future.result()
File "test_push_notifications.py", line 19, in send_push
r = await client.post("https://api.sandbox.push.apple.com:2197/3/device/4c526af3e9cd29cc0c6f8954de5f68fd1d00348696fe4a984581e35f19fe1ddf", data = payload)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_client.py", line 1848, in post
return await self.request(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 131, in __exit__
self.gen.throw(type, value, traceback)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.RemoteProtocolError: <ConnectionTerminated error_code:ErrorCodes.NO_ERROR, last_stream_id:0, additional_data:7b22726561736f6e223a22426164436572746966>
Can someone please help me navigate this error and send a successful request to APNS?
Valid Response:
import requests
with requests.Session() as req:
req.auth = authdata
req.headers.update({
'x-amz-access-token': access
})
r = req.get(
'https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
print(r)
But using httpx am getting:
import httpx
async with httpx.AsyncClient(timeout=None) as client:
client.auth = authdata
client.headers.update({
'x-amz-access-token': access
})
r = await client.get('https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
print(r)
Full Traceback:
Traceback (most recent call last):
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 60, in <module>
trio.run(main)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\trio\_core\_run.py", line 1932, in run
raise runner.main_task_outcome.error
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 56, in main
await get_orders(authdata, await get_token())
File "c:\Users\AmericaN\Desktop\Lab\code.py", line 49, in get_orders
r = await client.get('https://sellingpartnerapi-na.amazon.com/orders/v0/orders/', params=params)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1539, in get
return await self.request(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1361, in request
response = await self.send(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1396, in send
response = await self._send_handling_auth(
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_client.py", line 1428, in _send_handling_auth
request = await auth_flow.__anext__()
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_auth.py", line 92, in async_auth_flow
request = next(flow)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\httpx\_auth.py", line 115, in auth_flow
yield self._func(request)
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\site-packages\requests_auth_aws_sigv4\__init__.py", line 109, in __call__
p = urlparse(r.url)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 389, in urlparse
url, scheme, _coerce_result = _coerce_args(url, scheme)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 125, in _coerce_args
return _decode_args(args) + (_encode_result,)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in _decode_args
return tuple(x.decode(encoding, errors) if x else '' for x in args)
File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in <genexpr>
return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'URL' object has no attribute 'decode'
Solved By using the following : httpx-auth
I'm not familiar with Python testing, particularly with using mocks so this may be completely wrong.
I have this code in my test:
import os
import mock
from mock import Mock
from tests import unittest
from datetime import datetime
from ibm_botocore.session import Session
import logging
class TestS3Parameters(unittest.TestCase):
def setUp(self):
super(TestS3Parameters, self).setUp()
# Set the config file to something that doesn't exist so
# that we don't accidentally load a config.
os.environ['AWS_CONFIG_FILE'] = '~/.aws/config-missing'
def create_session(self, *args, **kwargs):
"""
Create a new session with the given arguments. Additionally,
this method will set the credentials file to the test credentials
used by the following test cases.
"""
kwargs['session_vars'] = {
'credentials_file': (
None, None,
os.path.join(os.path.dirname(__file__), 'test-credentials'),
None)
}
return Session(*args, **kwargs)
#mock.patch('ibm_botocore.credentials.Credentials')
def test_extended_endpoint(self, my_mock):
now = datetime.utcnow().strftime("%Y%m%d")
extended_listing_mock_response_basic = {
"IsTruncated": False,
"Buckets": [
{
"Name": "bucketnamefoo",
"CreationDate": str(now),
"LocationConstraint": "bar-standard"
}
],
"Owner": {
"DisplayName": "ownerfoo",
"ID": "idfoo"
}
}
s = self.create_session()
client = s.create_client('s3', region_name='us-east-1', aws_access_key_id='foo',
aws_secret_access_key='bar')
# Create a mock response.
self.mock_response = Mock()
self.mock_response = extended_listing_mock_response_basic
request = my_mock.list_bucket()
self.assertEquals(request['httpRequest']['method'], 'GET')
self.assertEquals(request['httpRequest']['path'], '/?extended')
if __name__ == "__main__":
unittest.main()
When I run it I get this error:
Traceback (most recent call last):
File "/core/.tox/py33/lib/python2.7/site-packages/mock/mock.py", line 1305, in patched
return func(*args, **keywargs)
File "/core/tests/unit/test_s3_param.py", line 56, in test_extended_endpoint
request = client.list_bucket()
File "/core/ibm_botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/core/ibm_botocore/client.py", line 648, in _make_api_call
operation_model, request_dict, request_context)
File "/core/ibm_botocore/client.py", line 667, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "/core/ibm_botocore/endpoint.py", line 102, in make_request
return self._send_request(request_dict, operation_model)
File "/core/ibm_botocore/endpoint.py", line 132, in _send_request
request = self.create_request(request_dict, operation_model)
File "/core/ibm_botocore/endpoint.py", line 116, in create_request
operation_name=operation_model.name)
File "/core/ibm_botocore/hooks.py", line 356, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "/core/ibm_botocore/hooks.py", line 228, in emit
return self._emit(event_name, kwargs)
File "/core/ibm_botocore/hooks.py", line 211, in _emit
response = handler(**kwargs)
File "/core/ibm_botocore/signers.py", line 90, in handler
return self.sign(operation_name, request)
File "/core/ibm_botocore/signers.py", line 157, in sign
auth.add_auth(request)
File "/core/ibm_botocore/auth.py", line 425, in add_auth
super(S3SigV4Auth, self).add_auth(request)
File "/core/ibm_botocore/auth.py", line 368, in add_auth
signature = self.signature(string_to_sign, request)
File "/core/ibm_botocore/auth.py", line 349, in signature
request.context['timestamp'][0:8])
File "/core/ibm_botocore/auth.py", line 169, in _sign
sig = hmac.new(key, msg.encode('utf-8'), sha256).digest()
File "/Users/me/.pyenv/versions/2.7.8/lib/python2.7/hmac.py", line 136, in new
return HMAC(key, msg, digestmod)
File "/Users/me/.pyenv/versions/2.7.8/lib/python2.7/hmac.py", line 75, in __init__
self.outer.update(key.translate(trans_5C))
TypeError: must be convertible to a buffer, not MagicMock
How do I convert this to a type I can use?
I tried using request = my_mock.list_bucket() but it give me this error:
AssertionError: <MagicMock name='Credentials.list_buckets_extended().__getitem__().__getitem__()' id='4459954832'> != 'GET'
What I'm trying to do is create a mock client which I can use for my list_bucket call. I then hope to check it to ensure the request is a GET and the /?extended endpoint is used.
I'm hitting some unintuitive behavior in solidity when one of my contracts calls another. I'm testing the contracts with web3py. Here's is the most minimal example I could come up with. Note that it may not actually be a minimal example because failures reasons aren't propagated from ethereum to web3py.
Foo.sol:
pragma solidity ^0.4.0;
import "./Bar.sol";
contract Foo {
Bar public bar;
function Foo(){
bar = new Bar();
}
function test() returns (uint) { return 1; }
function test2() {}
function execute() {
bar.run();
}
}
Bar.sol
pragma solidity ^0.4.0;
import "./Foo.sol";
contract Bar {
address bar_address;
function Bar(){
bar_address = msg.sender;
}
function run() {
Foo foo = Foo(bar_address);
// foo.test(); # fails
foo.test2(); # succeeds
}
}
test.py
from web3 import Web3, EthereumTesterProvider
import unittest
import os
from eth_tester.exceptions import TransactionFailed
import tests.utils.utils as utils
from web3.utils.filters import Filter
class TestMycroToken(unittest.TestCase):
PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
CONTRACT_ROOT = os.path.join(PROJECT_ROOT, "contracts")
TEST_CONTRACT_ROOT = os.path.join(CONTRACT_ROOT, "test_contracts")
def test_foo(self):
w3 = Web3(EthereumTesterProvider())
proposal_contract, proposal_contract_address, proposal_contract_instance = utils.create_contract(
self.CONTRACT_ROOT, os.path.join(self.TEST_CONTRACT_ROOT, "Foo.sol"), "Foo", w3 )
proposal_contract_instance.execute(transact={'from': self.w3.eth.accounts[1]})
When Bar.run calls Foo.test2() the test passes, but when Foo.test() is called, the test fails.
utils.create_contract more or less does what's shown in the quickstart for web3py with some modifications to handle compiling multiple files.
I'm getting the following stack trace for the error:
/Users/paymahn/mycro/venv/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/_jb_unittest_runner.py --target test_mycro_token.TestMycroToken.test_foo
Launching unittests with arguments python -m unittest test_mycro_token.TestMycroToken.test_foo in /Users/paymahn/mycro/tests
Ran 1 test in 0.692s
FAILED (errors=1)
Error
Traceback (most recent call last):
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/eth_tester/utils/formatting.py", line 85, in wrapper
return to_wrap(*args, **kwargs)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/eth_tester/backends/pyethereum/v16/main.py", line 439, in estimate_gas
transaction=transaction,
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/eth_tester/backends/pyethereum/v16/main.py", line 157, in _estimate_evm_transaction
return _send_evm_transaction(tester_module, evm, transaction_for_estimate)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/eth_tester/backends/pyethereum/v16/main.py", line 145, in _send_evm_transaction
evmdata=transaction.get('data', b''),
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/ethereum/tester.py", line 338, in send
return self._send(*args, **kwargs)["output"]
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/ethereum/tester.py", line 296, in _send
raise TransactionFailed()
ethereum.tester.TransactionFailed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File "/Users/paymahn/mycro/tests/test_mycro_token.py", line 125, in test_foo
proposal_contract_instance.execute(transact={'from': self.w3.eth.accounts[1]})
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/contract.py", line 777, in __call__
return self.__prepared_function(*args, **kwargs)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/contract.py", line 790, in __prepared_function
return getattr(self._function(*args), modifier)(modifier_dict)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/contract.py", line 1028, in transact
**self.kwargs)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/contract.py", line 1305, in transact_with_contract_function
txn_hash = web3.eth.sendTransaction(transact_transaction)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/eth.py", line 247, in sendTransaction
get_buffered_gas_estimate(self.web3, transaction),
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/utils/transactions.py", line 72, in get_buffered_gas_estimate
gas_estimate = web3.eth.estimateGas(gas_estimate_transaction)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/eth.py", line 288, in estimateGas
[transaction],
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/manager.py", line 103, in request_blocking
response = self._make_request(method, params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/manager.py", line 86, in _make_request
return request_func(method, params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/gas_price_strategy.py", line 18, in middleware
return make_request(method, params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 21, in middleware
response = make_request(method, formatted_params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/attrdict.py", line 18, in middleware
response = make_request(method, params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 21, in middleware
response = make_request(method, formatted_params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/normalize_errors.py", line 9, in middleware
result = make_request(method, params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/validation.py", line 44, in middleware
return make_request(method, post_validated_params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 21, in middleware
response = make_request(method, formatted_params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/providers/eth_tester/middleware.py", line 315, in middleware
return make_request(method, [filled_transaction] + params[1:])
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/fixture.py", line 12, in middleware
return make_request(method, params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/middleware/formatting.py", line 21, in middleware
response = make_request(method, formatted_params)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/providers/eth_tester/main.py", line 46, in make_request
response = delegator(self.ethereum_tester, params)
File "cytoolz/functoolz.pyx", line 232, in cytoolz.functoolz.curry.__call__
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/web3/providers/eth_tester/defaults.py", line 36, in call_eth_tester
return getattr(eth_tester, fn_name)(*fn_args, **fn_kwargs)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/eth_tester/main.py", line 466, in estimate_gas
raw_gas_estimate = self.backend.estimate_gas(raw_transaction)
File "/Users/paymahn/mycro/venv/lib/python3.6/site-packages/eth_tester/utils/formatting.py", line 88, in wrapper
raise old_to_new_exceptions[type(e)] from e
eth_tester.exceptions.TransactionFailed
I use Tornado AsynchHTTPClient().fetch(url, method="POST",body=body,headers=headers) with coroutine,but an error thrown:
TypeError: Expected bytes, unicode, or None; got type 'int'
#gen.coroutine
def do_post(self, url, data):
self.checksum_builder()
headers = {
'AppKey': self.app_key,
'Nonce': self.nonce,
'CurTime': self.current_time,
'CheckSum': self.checksum,
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
}
postdata = data
http_client = AsyncHTTPClient()
print urllib.urlencode(postdata)
response = yield http_client.fetch(url, method='POST', headers=headers, body=urllib.urlencode(postdata))
print response.error
raise gen.Return(response)
#gen.coroutine
def create_nim_id(self, accid, name='', props='', icon='', token=''):
data = dict({
'accid':accid,
'name':name,
'props':props,
'icon':icon,
'token':token
})
response = yield self.do_post(self.create_nim_id_url, data)
raise gen.Return(response)
#gen.coroutine
def get(self, *args, **kwargs):
result = yield netease_im_api.NeteaseAPI().create_nim_id(accid='moonmoonbird1',icon='2',props='321',token='adsadsadsadsd', name='hello')
print(result)
[E 160504 20:32:39 web:1524] Uncaught exception GET
/card/8/76d27dfa11cf11e69d86a45e60dcaf9d (127.0.0.1)
HTTPServerRequest(protocol='http', host='127.0.0.1:8000', method='GET', uri='/card/8/76d27dfa11cf11e69d86a45e60dcaf9d',
version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Host':
'127.0.0.1:8000', 'Cookie':
'_xsrf=2|1d0561f1|3c717ed824bff16dc8f804b0a7c990ca|1462268491',
'Connection': 'close', 'User-Agent': 'Paw/2.2.9 (Macintosh; OS
X/10.11.2) GCDHTTPRequest'})
Traceback (most recent call last):
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/web.py",
line 1445, in _execute
result = yield result
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1008, in run
value = future.result()
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/concurrent.py",
line 232, in result
raise_exc_info(self._exc_info)
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1014, in run
yielded = self.gen.throw(*exc_info)
File "/Users/moonmoonbird/Documents/kuolie/kuolie/account/utils.py", line
70, in wrapper
ret = yield ret
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1008, in run
value = future.result()
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/concurrent.py",
line 232, in result
raise_exc_info(self._exc_info)
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1014, in run
yielded = self.gen.throw(*exc_info)
File "/Users/moonmoonbird/Documents/kuolie/kuolie/wall/handlers.py", line
129, in get
result = yield netease_im_api.NeteaseAPI().create_nim_id(accid='moonmoonbird1',icon='2',props='321',token='adsadsadsadsd',
name='hello')
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1008, in run
value = future.result()
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/concurrent.py",
line 232, in result
raise_exc_info(self._exc_info)
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1014, in run
yielded = self.gen.throw(*exc_info)
File "/Users/moonmoonbird/Documents/kuolie/kuolie/neteaseim/netease_im_api.py",
line 84, in create_nim_id
response = yield self.do_post(self.create_nim_id_url, data)
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1008, in run
value = future.result()
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/concurrent.py",
line 232, in result
raise_exc_info(self._exc_info)
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1014, in run
yielded = self.gen.throw(*exc_info)
File "/Users/moonmoonbird/Documents/kuolie/kuolie/neteaseim/netease_im_api.py",
line 60, in do_post
response = yield http_client.fetch(url, method='POST', headers=headers, body=urllib.urlencode(postdata))
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/gen.py",
line 1008, in run
value = future.result()
File "/Users/moonmoonbird/Documents/kuolie/lib/python2.7/site-packages/tornado/concurrent.py",
line 232, in result
raise_exc_info(self._exc_info)
File "", line 3, in raise_exc_info
TypeError: Expected bytes, unicode, or None; got type int
I cant find where i am wrong, can someone help me,thanks in advance.