I'm trying to integrate Pagseguro (a brazilian payment service, similar to PayPal) with this lib
https://github.com/rochacbruno/python-pagseguro
But, I don't know how to access the data from notification that the service sends to me. This is my code:
notification_code = request.POST['notificationCode']
pg = PagSeguro(email="testPerson#gmail.com", token="token")
notification_data = pg.check_notification(notification_code)
print notification_data['status']
In the las line I receive this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'PagSeguroNotificationResponse' object has no attribute '__getitem__'
The documentation in the README doesn't seem to match the code. It looks like rather than notication_data being a dictionary it is an object that has attributes matching the dictionary keys from the README.
So this should work if you just change print notification_data['status'] to the following:
print notification_data.status
Related
I am really new with ontologies especially with owlready2. I loaded an Ontology the basic example Pizza and imported I think successfully on python (I checked whether I can see the classes which I can so..)
Than I used the following code to search one class specifically with the method search():
from owlready2 import *
onto_path.append(r"C:/Users/AyselenKuru/Desktop/owl_docs/owlpizza.owl")
onto=get_ontology(r"C:/Users/AyselenKuru/Desktop/owl_docs/owlpizza.owl")
onto.load()
am= onto.search_one(is_a= onto.American)
for x in onto.classes():
print(x)
I want to know how can I search/get one specific Class and an Attribute and I get the following error message:
Traceback (most recent call last):
File "c:\Users\AyselenKuru\Desktop\pizza_ex1.py", line 6, in <module>
am= onto.search_one(is_a = onto.American)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AyselenKuru\AppData\Local\Programs\Python\Python311\Lib\site-packages\owlready2\namespace.py", line 395, in search_one
def search_one(self, **kargs): return self.search(**kargs).first()
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AyselenKuru\AppData\Local\Programs\Python\Python311\Lib\site-packages\owlready2\namespace.py", line 364, in search
else: v2 = v.storid
^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'storid'
Problem solved itself, the example owl File had errors with IRI that caused a Problem with the search
I'm currently learning how to code in python and I was trying to raise exceptions in my code to make my tool more user-friendly. However, I find the template given by Maya to be too simple and I'd like to have more control over it.
Normally, the base template looks a little like this:
raise Exception(errorTitle)
>>> Result
# Error: errorTitle
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# Exception: errorTitle #
It works fine, but it doesn't let you give a more detailed description of the error. What I'm trying to achieve would look a little more like this:
raise Exception(errorTitle, errorDescription)
>>> Result
# Error: errorTitle
# errorDescription
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# Exception: errorTitle #
I also tried putting the errorDescription into errorTitle by adding a new line to the string, but since errorTitle is repeated twice, it becomes confusing quickly when trying to sort errors.
I know you can't really use multiple arguments in the raise function, so I was wondering if there was an error template in Maya I could reference instead of raising an error.
Alternatively, is there a way to create my own error template? If I can reuse the Traceback function and change the script bar color, it might be easier to just do that.
Thanks in advance!
You can get your desired result just like that:
>>> raise Exception("Error Title\nError description that explains the problem")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: Error Title
Error description that explains the problem
Or you may want to declare your custom exception class:
class YourException(Exception):
def __init__(self, title, description):
super(YourException, self).__init__(title + "\n" + description)
and then you can use your original syntax:
>>> raise YourException("Error Title", "Error description that explains the problem")
File "<stdin>", line 1, in <module>
__main__.YourException: Error Title
Error description that explains the problem
When I copy the below code in Ideone then it runs fine but it is not running in the text editor and showing the error mentioned in the subject of this post:
import calendar
c = calendar.TextCalendar(calendar.SUNDAY)
c.prmonth(2007, 7)
The complete error is:
Traceback (most recent call last):
File "calendar.py", line 1, in <module>
import calendar
File "/home/shl/Desktop/calendar.py", line 2, in <module>
c = calendar.TextCalendar(calendar.SUNDAY)
AttributeError: 'module' object has no attribute 'TextCalendar'
change the program name from calendar.py to something like calendar_code.py
This wold work properly.
Importing from builtin library when module with same name exists
This is a script I have that reads a JSON file and adds routes to a graph
for route in data['routes']:
route = Route(route['ports'][0], route['ports'][1], route['distance'])
self.add_route(route)
route_2 = Route (route['ports'][1], route['ports'][0], route['distance'])
self.add_route(route_2)
It gives me this error:
Traceback (most recent call last):
File "C:\workspace\Assignment2.1\src\Main.py", line 75, in <module>
graph.build_from_file()
File "C:\workspace\Assignment2.1\src\Graph.py", line 195, in build_from_file
route_2 = Route (route['ports'][1], route['ports'][0], route['distance'])
TypeError: 'Route' object is not subscriptable
Notice it gives an error at the second call of the Route constructor not first.
Can anyone help me out with this?
You named two different things route.
After you created your first Route, the route variable is pointing to it instead of your datum.
Fixed code:
for route in data['routes']:
route_1 = Route(route['ports'][0], route['ports'][1], route['distance'])
self.add_route(route_1)
route_2 = Route(route['ports'][1], route['ports'][0], route['distance'])
self.add_route(route_2)
Recently I've got this problem in my application:
File "main.py", line 31,
in File "app.pyc", line 205, in run
TypeError: 'NoneType' object is not callable"
My code:
xml = EXML()
for pid, product in store.products.items():
xml.addRow()
xml.addCell((product['name']).encode('utf-8'), "String")
xml.addCell((product['symbol']).encode('utf-8'), "String")
xml.addCell((product['brand_name']).encode('utf-8'), "String") # line 205
xml.addCell(str(product['price']), "String")
Python 2.7 32-bit
It's wired, because this showed up after ~1000 iterations, with out any previus problem.
This application scans online store to get current prices.
Firstly I thought that somewhere I missed someting, and as result there is None.encode('utf-8'), but no, and "".encode('utf-8') seems to work. Moreover, I can't reproduce this error on testing site, just sometimes shows up while hard-working with ~2500 products.
What are possible other sources of this error?
>>> None.encode
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'encode'
>>> None()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
On the given line you would have to set one of the two functions called to None somehow. Are you sure it's not the next line, because overwriting str is a rather common error.
OK, solved, it's bit bizzare, but this error is caused by product['brand_name'] which is sometimes BeautifulSoup.tag ( tag this time ) instead of BeautifulSoup.NavigableString as I planned. I still don't understad why and wtf ?
Anywat, great thanks for response. :)