I am getting
TypeError: unhashable type: 'list'
when I try to run the example from the boto documentation:
results = mytable.batch_get(keys=[{'username':'johndoe'},{'username':'jane'},{'username':'fred'},])
for res in results:
print res['username']
I don't see anything I could have done wrong, but obviously there is something.
Any suggestions?
edit, adding stacktrace:
Traceback (most recent call last):
File "testdynamolocal.py.bak", line 25, in <module>
for res in results:
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/boto/dynamodb2/results.py", line 62, in __next__
self.fetch_more()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/dynamodb2/results.py", line 183, in fetch_more
results = self.the_callable(*args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto/dynamodb2/table.py", line 1337, in _batch_get
'Keys': [],
TypeError: unhashable type: 'list'
Turned out to be a mistake in getting 'mytable', posting here in case anyone else has a similar bad time:
I was doing this:
for table in tables.values():
mytable = Table(table, connection=conn)
results = mytable.batch_get(keys=[{'username':'johndoe'},{'username':'jane'},{'username':'fred'},])
...
But 'table' was getting a list instead of a string from tables.values(), so this works:
mytable = Table(table[0], connection=conn)
I am not thrilled with where the error was actually surfacing, but totally a problem I should have seen earlier.
Related
I have a problem with executing the function processing.results() in oemof.
It was working before, but after an update it didn't work any more.
Does anyone know how to fix it or which interpreter I need for oemof - oemof test says all is installed correct. Or is my code wrong?
Code:
64/# OPTIMIZATION MODEL
65/equipmentList = (electricity_bus, heat_bus, electricity_grid, electricity_supply,
electricity_storage, heat_supply, heat_storage, heat_pump, photovoltaics, excess_electricity)
66/for item in equipmentList:
67/ optimizationSystem.add(item)
68/model = solph.Model(optimizationSystem)
69/model.write('optimizationSystem_model.lp', io_options={'symbolic_solver_labels': True})
70/model.solve(solver='gurobi', solve_kwargs={'tee': True})
71/results = solph.processing.results(model)
Failure-Message:
Traceback (most recent call last):
File "C:/Users/TKurz/Desktop/NEFI Hackathon/Main.py", line 71, in <module>
results = solph.processing.results(model)
File "C:\Users\TKurz\AppData\Local\Programs\Python\Python38\lib\site-packages\oemof\solph\processing.py", line 125, in results
df = create_dataframe(om)
File "C:\Users\TKurz\AppData\Local\Programs\Python\Python38\lib\site-packages\oemof\solph\processing.py", line 89, in create_dataframe
for i in getattr(bv, "_index"):
AttributeError: 'IndexedVar' object has no attribute '_index'
THX for any help!
Yours Thomas
i'm using replits database but when i try to load it in it returns an error
any ideas?
cookie = db[name]
cookiepc = db[name + "cookiepc"]
increase = db[name + "increase"]
the error is
Traceback (most recent call last):
File "main.py", line 25, in <module>
cookiepc = db[name + "cookiepc"]
File "/home/runner/Cookie-clicker/venv/lib/python3.8/site-packages/replit/database/database.py", line 439, in __getitem__
raw_val = self.get_raw(key)
File "/home/runner/Cookie-clicker/venv/lib/python3.8/site-packages/replit/database/database.py", line 479, in get_raw
raise KeyError(key)
KeyError: 'shdfgwbdhfbadwcookiepc'
According to the documentation for replit-py, a KeyError is raised when an attempt is made to read from a key that doesn't exist in the database.
You can use db.get to specify a default value for if the key doesn't exist:
print(db.get("b", "default")) # default
db["b"] = "pie"
print(db.get("b", "default")) # pie
im trying to generate a pdf file from this code i typed str but dosent work with me still got the same erorr.
reshaped_text3 = str(arabic_reshaper.reshape(flatmeate1.pays(bill, flatmate2)))
bidi_text3 = str(get_display(reshaped_text3))
pdf.drawCentredString(290, 270, bidi_text3)
print("Mohamed Pays", mohamed.pays(bill=the_bill, flatmate2=marry))
print("Marry Pays", marry.pays(bill=the_bill, flatmate2=mohamed))
pdf_report = PdfReport(filename='tarek.pdf')
pdf_report.generate(flatmeate1=mohamed, flatmate2=marry, bill=the_bill)
traceback
Traceback (most recent call last):
File "C:\Users\20102\PycharmProjects\bill-project\main.py", line 85, in <module>
pdf_report.generate(flatmate1=mohamed, flatmate2=marry, bill=the_bill)
File "C:\Users\20102\PycharmProjects\bill-project\main.py",
line 64, in generate reshaped_text3 = str(arabic_reshaper.reshape(flatmate1.pays(bill, flatmate2)))
File "C:\Users\20102\PycharmProjects\bill-project\venv\lib\site-packages\arabic_reshaper\arabic_reshaper.py",
line 125, in reshape for letter in text:
TypeError: 'float' object is not iterable
I have made this code, to get the year from an mp3, and if i print it, it works, but when i write to text box in my webpage, it gives an error(traceback below), but not always, sometimes the error not show, so i suspect it is from the way the mp3 is tagged:
nfo_year = ''
audio_filename = 'myfile.mp3'
f = mutagen.File(audio_filename)
audio = ID3(audio_filename) # path: path to file
# Year
try:
nfo_year = audio['TDRC'].text[0]
print(nfo_year)
except:
pass
time.sleep(2)
logger_internet.info('Writing Year...')
AB_author = driver.find_element_by_name('year')
AB_author.send_keys(nfo_year)
Traceback (most recent call last):
File "D:\AB\redacted.py", line 1252, in <module>
AB_author.send_keys(nfo_year)
File "D:\AB\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 478, in send_keys
{'text': "".join(keys_to_typing(value)),
File "D:\AB\venv\lib\site-packages\selenium\webdriver\common\utils.py", line 150, in keys_to_typing
for i in range(len(val)):
TypeError: object of type 'ID3TimeStamp' has no len()
my question is: an error on the mp3 tag or am i doing something wrong?
nfo_year is a timestamp object, of type ID3TimeStamp. You have to pass strings to AB_author.send_keys. Since print worked, you can try str(nfo_year).
I have a scrapy script that works locally, but when I deploy it to Scrapinghub, it's giving all errors. Upon debugging, the error is coming from Yielding the item.
This is the error I get.
ERROR [scrapy.utils.signal] Error caught on signal handler: <bound method ?.item_scraped of <sh_scrapy.extension.HubstorageExtension object at 0x7fd39e6141d0>> Less
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 150, in maybeDeferred
result = f(*args, **kw)
File "/usr/local/lib/python2.7/site-packages/pydispatch/robustapply.py", line 55, in robustApply
return receiver(*arguments, **named)
File "/usr/local/lib/python2.7/site-packages/sh_scrapy/extension.py", line 45, in item_scraped
item = self.exporter.export_item(item)
File "/usr/local/lib/python2.7/site-packages/scrapy/exporters.py", line 304, in export_item
result = dict(self._get_serialized_fields(item))
File "/usr/local/lib/python2.7/site-packages/scrapy/exporters.py", line 75, in _get_serialized_fields
value = self.serialize_field(field, field_name, item[field_name])
File "/usr/local/lib/python2.7/site-packages/scrapy/exporters.py", line 284, in serialize_field
return serializer(value)
File "/usr/local/lib/python2.7/site-packages/scrapy/exporters.py", line 290, in _serialize_value
return dict(self._serialize_dict(value))
File "/usr/local/lib/python2.7/site-packages/scrapy/exporters.py", line 300, in _serialize_dict
key = to_bytes(key) if self.binary else key
File "/usr/local/lib/python2.7/site-packages/scrapy/utils/python.py", line 117, in to_bytes
'object, got %s' % type(text).__name__)
TypeError: to_bytes must receive a unicode, str or bytes object, got int
It doesn't specify the field with issues, but by process of elimination, I came to realize it's this part of the code:
try:
item["media"] = {}
media_index = 0
media_content = response.xpath("//audio/source/#src").extract_first()
if media_content is not None:
item["media"][media_index] = {}
preview = item["media"][media_index]
preview["Media URL"] = media_content
preview["Media Type"] = "Audio"
media_index += 1
except IndexError:
print "Index error for media " + item["asset_url"]
I cleared some parts up to make it easier to tackle, but basically this part is the issue. Something it doesn't like about the item media.
I'm beginner in both Python and Scrapy. So sorry if this turns out to be silly basic Python mistake. Any idea?
EDIT: So after getting the answer from ThunderMind, the solution was to simply do str(media_index) for key
Yeah, right here:
item["media"][media_index] = {}
media_index is a mutable. and Keys can't be mutable.
Read Python dict, to know what should be used as keys.