Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

Incorrect attribute names in GetBalancesCommand response (using sandbox example script) #55

Closed
johngrantuk opened this issue Jul 21, 2017 · 8 comments
Assignees
Labels

Comments

@johngrantuk
Copy link
Contributor

PyOTA 1.1.3

Python 2.7.10

Mac OS El Capitan 10.11.6

Description:
Running sandbox example. iota.send_transfer gives following error: TypeError: 'NoneType' object is not iterable

Traceback:
Traceback (most recent call last):
File "sandbox.py", line 51, in
message = TryteString.from_string('Hello, Tangle!'),
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/api.py", line 822, in send_transfer
minWeightMagnitude = min_weight_magnitude,
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/commands/init.py", line 122, in call
self.response = self._execute(self.request)
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/commands/extended/send_transfer.py", line 46, in _execute
transfers = transfers,
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/commands/init.py", line 122, in call
self.response = self._execute(self.request)
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/commands/extended/prepare_transfer.py", line 54, in _execute
threshold = want_to_spend,
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/commands/init.py", line 122, in call
self.response = self._execute(self.request)
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/commands/extended/get_inputs.py", line 62, in _execute
for i, balance in enumerate(gb_response['balances']):
TypeError: 'NoneType' object is not iterable

Possible fix? (Creating a Pull request)
In get_inputs.py, Line 51, gb_response = GetBalancesCommand( ) is returning: {u'MilestoneIndex': 123423, …. u'Duration': 0, u'Balances': [0, 0, 41, 0, 0, 0]}

Line 62 uses: enumerate(gb_response['balances'])

Changing 'balances' to 'Balances' seems to fix the problem.

@todofixthis
Copy link
Contributor

todofixthis commented Jul 22, 2017

Hi @johngrantuk! Thanks for reporting this issue!

This looks like a problem with the sandbox node. Could I ask you to collect a little extra debugging info?

Please run the following commands:

from iota import *
from iota.adapter.sandbox import SandboxAdapter

iota =\
  Iota(
    adapter = SandboxAdapter(
      uri = 'https://sandbox.iota.org/api/v1/',

      # Replace with your auth token.
      auth_token = 'auth token goes here',
    ),
  )

import logging, sys
logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)
iota.api.set_logger(logging.getLogger(__name__))

iota.get_balances([b'A'])

You can scrub out your auth token if it appears in the debug output; what I'm most interested in is the raw response payload from the sandbox. It appears that the sandbox is incorrectly capitalising the attribute names, but I need to confirm.

@todofixthis todofixthis changed the title get_inputs.py Issue (Using Sandbox) Incorrect attribute names in GetBalancesCommand response (using sandbox example script) Jul 22, 2017
@johngrantuk
Copy link
Contributor Author

I had to add from future import absolute_import, division, print_function, unicode_literals otherwise I got "AttributeError: 'str' object has no attribute 'scheme'". With this added the output is:

Traceback (most recent call last):
File "debug.py", line 18, in
iota.api.set_logger(logging.getLogger(name))
File "/Users/johngrant/Downloads/iota/env/lib/python2.7/site-packages/iota/api.py", line 103, in getattr
command = command,
iota.api.InvalidCommand: Iota does not support 'api' command.

@todofixthis
Copy link
Contributor

Ahhh, shoot. Sorry about that; I copied the wrong command. It should be iota.adapter.set_logger. This is the corrected code:

from iota import *
from iota.adapter.sandbox import SandboxAdapter

iota =\
  Iota(
    adapter = SandboxAdapter(
      uri = u'https://sandbox.iota.org/api/v1/',

      # Replace with your auth token.
      auth_token = 'auth token goes here',
    ),
  )

import logging, sys
logging.basicConfig(level=logging.DEBUG, stream=sys.stderr)
iota.adapter.set_logger(logging.getLogger(__name__))

iota.get_balances([b'A'])

@johngrantuk
Copy link
Contributor Author

All good. New output below:

DEBUG:main:Sending post to https://sandbox.iota.org/api/v1/commands: '{"threshold": 100, "command": "getBalances", "addresses": ["A99999999999999999999999999999999999999999999999999999999999999999999999999999999"]}'
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): sandbox.iota.org
DEBUG:urllib3.connectionpool:https://sandbox.iota.org:443 "POST /api/v1/commands HTTP/1.1" 200 150
DEBUG:main:Receiving post from https://sandbox.iota.org/api/v1/commands: '{"Duration":0,"Balances":[0],"Milestone":"SYMOPFBXCXQMLGKKCVX9NFZCIBDRIKPRJFPASJYHWPYPVFEOUMZABQLRXJMETXCDDBOVLDTPOZDL99999","MilestoneIndex":127002}\n'

@todofixthis
Copy link
Contributor

Thanks John!

Hmm... that's interesting. Looks like the sandbox node is using the wrong case for attribute names in the response after all.

I'm-a ping Dom about this to see if this is an issue with the sandbox, or if the attribute names changed in a recent version of the IRI. As soon as I find out what's up, fixing this issue will be top priority.

@todofixthis todofixthis self-assigned this Jul 24, 2017
@jinnerbichler
Copy link
Contributor

Any news on this one?

According to the getNodeInfo the IRI version of the sandbox is 1.4.0.

Calling getBalances on the sandbox returns

{
    "Duration": 0,
    "Balances": [0],
    "Milestone": "RXTDTARWZPYTWBFXDHGZDTCDYBWGMKAHDKIAYKKKGUTUNJAXIVIKYDVCTVE9WGJ9GAPFCEZOFYZPA9999",
    "MilestoneIndex": 233555
}

whereas running IRI v.1.4.0 locally (either via Java or Docker) returns

{
    "duration": 6,
    "balances": ["0"],
    "milestone": "999999999999999999999999999999999999999999999999999999999999999999999999999999999",
    "milestoneIndex": 217000
}

There is definitely a difference. The first letter of each JSON key is capitalised. There might be an issue with the JSON serialiser at the sandbox runtime.

@todofixthis
Copy link
Contributor

todofixthis commented Oct 12, 2017

Hey guys. Sorry that this is taking so long to resolve! I've logged a couple of issues with the Sandbox and Go projects, and I bugged the IF folks again.

This one is a bit tricky to resolve because the issues appear to be caused by core libraries, rather than the sandbox code (thanks @jinnerbichler for the detective work on the capitalised JSON attributes!).

Keep an eye on these issues:

@todofixthis
Copy link
Contributor

I'm going to go ahead and close this issue, as it's not really a problem with PyOTA. Do keep an eye on the issues linked in the previous comment; if necessary, we can escalate this with the sandbox/iri teams on Discord.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants