why web3.eth.getBlock gives null answer and getTransactionReceipt gives error? - python

I am using Web3.py in my python code. The code is like this
from web3 import Web3
w3 = Web3(Web3.HTTPProvider("https://ropsten.infura.io/"))*
for i in range(5000000,5100000):
print(i)
transactionArray = []
blockResult = w3.eth.getBlock(i)
for tx in blockResult["transactions"]:
txResult = binascii.hexlify(tx).decode()
print(txResult)
transactionResult = w3.getTransactionReceipt(txResult)
print(transactionResult)
When I execute this code, getting error
5000000
Traceback (most recent call last):
File "Test06.py", line 27, in <module>
for tx in blockResult["transactions"]:
TypeError: 'NoneType' object is not subscriptable
but If I start range from 4571699 it gives me the result. Can somebody tell me why I'm getting an error for range starts from 5000000
I use the MAIN NET, so resolved this problem. But now I am getting an error as
Traceback (most recent call last):
File "Test06.py", line 35, in <module>
transactionResult = w3.getTransactionReceipt(txResult)
AttributeError: 'Web3' object has no attribute 'getTransactionReceipt'.

You're using the ropsten test chain which only has 4572019 blocks as of this answer.

Related

Unable to create owl:NamedIndividual on owlready2

I need to create a NamedIndividual (https://www.w3.org/TR/owl2-syntax/#Named_Individuals) but I am not seeing a way to do it.
The following example:
from owlready2 import *
onto = get_ontology("example")
class NamedIndividual(Thing): namespace = owl
print(NamedIndividual.iri)
print(NamedIndividual.name)
mini = NamedIndividual()
onto.save("minrep.rdf")
Gives the following error:
http://www.w3.org/2002/07/owl#NamedIndividual
NamedIndividual
Traceback (most recent call last):
File "minrep.py", line 13, in <module>
mini = NamedIndividual("example")
File "/home/lubianat/Documents/main_venv/lib/python3.8/site-packages/owlready2/individual.py", line 137, in __init__
if self.storid > 0: self.namespace.ontology._add_obj_triple_spo(self.storid, rdf_type, owl_named_individual)
TypeError: '>' not supported between instances of 'str' and 'int'
If I instantiate the class without a name, I get another error:
http://www.w3.org/2002/07/owl#NamedIndividual
NamedIndividual
Traceback (most recent call last):
File "minrep.py", line 13, in <module>
mini = NamedIndividual()
File "/home/lubianat/Documents/main_venv/lib/python3.8/site-packages/owlready2/individual.py", line 123, in __init__
iri = self.namespace.world._new_numbered_iri("%s%s" % (self.namespace._base_iri, self.generate_default_name()))
AttributeError: 'World' object has no attribute '_new_numbered_iri'
Any ideas on what is happening there? Thanks!

Error while working with sqlite3 in python

In my Python script, I am seeing the following error.
Traceback (most recent call last):
File "F:/python sqllite/test32.py", line 3,
in <module> conn.sqlite3.connect('test.db')
AttributeError: 'sqlite3.Connection' object has no attribute 'sqlite3'
Does anyone have an idea why I might be seeing this?
Change: conn.sqlite3.connect('test.db')
to : conn = sqlite3.connect('test.db')

'generator' object has no attribute error in accessing the tree levels in python

This is my code:
from nltk import load_parser
cp = load_parser('grammars/book_grammars/sql0.fcfg')
query = 'What cities are located in China'
trees = cp.parse(query.split())
answer = trees[0].node['sem']
Here is the error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'generator' object has no attribute '__getitem__'
Why it is giving such error, what is the solution of it?

why do I get the following error in get request

I have code like this :
import requests
import xmltodict
Locations = ['http://129.94.5.93:49154/setup.xml', 'http://129.94.5.92:49154/setup.xml', 'http://129.94.5.93:49154/setup.xml', 'http://129.94.5.92:49154/setup.xml', 'http://129.94.5.95:80/description.xml']
for item in Locations:
r = requests.get(item)
reply = xmltodict.parse(r.text)
this gives me the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ssdpxml.py", line 57, in <module>
r = requests.get(item)
AttributeError: 'str' object has no attribute 'get'
But it works when I do this:
r=requests.get('http://129.94.5.95:80/description.xml')
Why do I get the above mentioned error??

python rq Queue import error

I'm using python v2.7.3 - Installed python-rq via easy_install. While trying to create RQ queue with steps given at http://python-rq.org/ . it fails with message like
>>> from redis import Redis
>>> from rq import Queue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "rq.py", line 11, in <module>
q = Queue(connection=Redis())
TypeError: 'module' object is not callable
>>>
>>> q = Queue(connection=Redis())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Queue' is not defined
>>>
Whats the issue here and how to fix this?
Reposting comment as answer:
Thanks for the answer. Sorry stupid me! .sometime back I created file named rq.py and its creating problem. Deleted that file.solved the issue

Categories

Resources