AWS Personalize throws bad param error using context={...} - python

I am working with AWS Personalize and the Python SDK (boto3). All goes well until I try to include the context param in the request. While everything works as expected within the Personalize > Campaigns UI for testing the results, when I try to use the following code:
response = personalizeRt.get_recommendations(
campaignArn = 'arn:aws:personalize:XXXXXXXXXX:campaign/interactions-meta',
userId = '43f0c7fd-4d89-4752-9c88-2fe5bf7ac830',
context={
'GENRES' : '42'
}
)
I get the following error:
Unknown parameter in input: "context", must be one of: campaignArn, itemId, userId, numResults
Has anyone else seen this error? And if so, how did you resolve it.
Thanks in advance.

Seems the issue is the version of boto3/botocore within Pycharm. If I run the same code on the command line, all works as expected.
In Pycharm go to Preferences > Project Interpreter. and you can update boto3 there.

Related

Invalid AttributeDataType input, consider using the provided AttributeDataType enum

I am trying to create aws cognito user pool using aws cdk.
below is my code -
user_pool = _cognito.UserPool(
stack,
id="user-pool-id",
user_pool_name="temp-user-pool",
self_sign_up_enabled=True,
sign_in_aliases={
"username": False,
"email": True
},
required_attributes={
"email": True
}
)
I want to set "Attributes" section in User pool for email .
But above code gives me this exception -
Invalid AttributeDataType input, consider using the provided AttributeDataType enum. (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidParameterException; Request ID:
I have tried many scenarios but it didn't work. Am I missing something here. Any help would be appreciated. Thanks!
I was referring this AWS doc to create userpool - https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cognito/UserPool.html and https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cognito/RequiredAttributes.html#aws_cdk.aws_cognito.RequiredAttributes
According to a comment on this GitHub issue this error is thrown when an attempt is made to modify required attributes for a UserPool. This leaves you two options:
Update the code such that existing attributes are not modified.
Remove the UserPool and create a new one. E.g. cdk destroy followed by cdk deploy will recreate your whole stack (this is probably not what you want if your stack is in production).
https://github.com/terraform-providers/terraform-provider-aws/issues/3891
Found a way to get around it in production as well, where you don't need to recreate the user pool.

ReceivedTime of the mail is not showing in python

I am trying to read my mail and see the received time in outlook 2016 using MAPI.
I am able to see the subject of the mail not able to see the receivedTime of the mail. I know that "Receivedtime" is there to get the received time of the mail, but while the program is executed,
a popup is coming, telling that python has stopped working
I know it is not due to any machine problem rather some problem in my code.
Here is my code.
def arrange(mailbox):
global spam
timeperiod() # stores required date in spam[] list
msgs=mailbox.Items
msgs.Sort("[ReceivedTime]", True)
p=msgs.restrict(" [ReceivedTime] >= '"+spam[2]+"'") #and [ReceivedTime] >= '" +spam[1]+"'
print(len(p))
'''
for m in list1:
if m.Unread:
m.Unread=False
'''
return p
#Calling it
ctm1=arrange(ctm)
print(len(ctm1)) #Working fine
for message in ctm1:
print (message.subject) #Also works good
print (message.receivedTime) # Here is the problem, it's not showing
]1
i have tried Senton property as well, but it's not working . So any guesses why the senton or receivedTime properties are not working???
updated code :
def printlist(box1) :
print(len(box1))
for message in box1:
if message.Class==43 :
# print('true')
print (message)
#.senderEmailAddress) #working
#print(message.SentOn.strftime("%d-%m-%y")) #not working
#print(message.body)
#print(message.UnRead)
#print (message.receivedTime) #not working
#print('-----------')
I was also having trouble with the .ReceivedTime breaking the program when I compile the .py script to an .exe using auto-py-to-exe.
Here's where the error occurs underneath this try: statement
try:
received_year = str(email.ReceivedTime)[0:4]
received_month = str(email.ReceivedTime)[5:7]
received_day = str(email.ReceivedTime)[8:10]
This works PERFECTLY well inside of my IDE (PyCharm), but once I've compiled it to .exe, it breaks here.
I've updated pywin32 to the most up-to-date version (228) and also tried using 224 to see if it was a version issue (it wasn't).
BUT!! Going through this, I FOUND THE BUG! When you compile to .exe with auto-py-to-exe, it does not include the package "win32timezone" which the .ReceivedTime portion needs to run correctly. So you need to import this package for it to work.
All you have to do to fix this is include this at the top of your .py script before compiling to .exe:
import win32timezone
Let me know if this works for anyone else facing this issue!
Most likely you run into an item other than MailItem - you can also have ReportItem and MeetingItem objects in your Inbox; none of them expose the ReceivedTime property.
Check that message.Class property == 43 (olMail) before accessing any other MailItem specific properties.
Please try the below:
print([x.ReceivedTime for x in messages])

DynamicsGP eConnect: cannot connect to endpoint

I'm using IronPython to use eConnect's .NET API for integration of expense reports with GP.
When
result = conn.CreateTransactionEntity(connection_string, xml)
is executed, I get this error:
StandardError: Cannot connect to endpoint 'net.pipe://localhost/Microsoft/Dynamics/GP/eConnect/EntityOperations'
Does anyone know what would cause this sort of issue? This same code has worked on other machines without error but for some reason it won't agree with the eConnect configuration on this particular one.
You must turn off the RequireProxyService property, so your code is:
conn.RequireProxyService = false;
result = conn.CreateTransactionEntity(connection_string, xml)

Cant run Python Views on Couchdb

i started using couchdb with python-couchdb recently. The problem is when i use futon run my views written in python i get the following error message:
Error: os_process_error
{exit_status,1}
even for the default view it crashes.
def fun(doc):
yield None, doc
i haven't yet found much information regarding this issue so at this point im really lost. This is the log i get from couchdb:
{<0.3907.0>,crash_report,
[[{initial_call,{couch_file,init,['Argument__1']}},
{pid,<0.3907.0>},
{registered_name,[]},
{error_info,
{exit,
{os_process_error,{exit_status,1}},
[{gen_server,terminate,6},{proc_lib,init_p_do_apply,3}]}},
{ancestors,
[<0.3906.0>,couch_view,couch_secondary_services,couch_server_sup,
<0.33.0>]},
{messages,[]},
{links,[#Port<0.1483>,<0.3910.0>]},
{dictionary,[]},
{trap_exit,true},
{status,running},
{heap_size,377},
{stack_size,24},
{reductions,1423}],
[{neighbour,
[{pid,<0.3910.0>},
{registered_name,[]},
{initial_call,{couch_ref_counter,init,['Argument__1']}},
{current_function,{gen_server,loop,6}},
{ancestors,
[<0.3906.0>,couch_view,couch_secondary_services,
couch_server_sup,<0.33.0>]},
{messages,[]},
{links,[#Port<0.1483>,<0.3910.0>]},
{dictionary,[]},
{trap_exit,true},
{status,running},
{heap_size,377},
{stack_size,24},
{reductions,1423}],
[{neighbour,
[{pid,<0.3910.0>},
{registered_name,[]},
{initial_call,{couch_ref_counter,init,['Argument__1']}},
{current_function,{gen_server,loop,6}},
{ancestors,
[<0.3906.0>,couch_view,couch_secondary_services,
couch_server_sup,<0.33.0>]},
{messages,
[{'DOWN',#Ref<0.0.0.16475>,process,<0.3906.0>,
{os_process_error,{exit_status,1}}}]},
{links,[<0.3907.0>]},
{dictionary,[]},
{trap_exit,false},
{status,runnable},
{heap_size,233},
{stack_size,9},
{reductions,47}]}]]}}
Im running this on Ubuntu 10.04, with Django, couchdb and python-couchdb. The views on javascript works fine.
For couchdb-python query server exit status 1 means some error that.
What version of couchdb/couchdb-python you're uses?
Whats output will be if you run couchpy (or /usr/local/bin/couchpy or whatever you have setted in query_servers section for python key) directly from command line? Example as it should be:
$
~ $ couchpy
["reset"]
true
["add_fun", "def fun(doc): yield None, None"]
true
["map_doc", {}]
[[[null, null]]]
If p.2 works fine, try to enable CouchDB debug log level to trace query server commands and notice when it falls. If you're sure that this is a python query server bug, please write some story about it. Thanks(:
P.S. I hope that you have setup python query server correctly, but double things check never was useless(;

Determining Exact Reason for Facebook Error Code 100

I am experimenting with facebook and trying to create an event, via the Graph API. I am using django and the python-facebook-sdk from github. I can successfully post to my wall pull friends etc.
I am using django-social-auth for facebook login stuff and have settings.py for permissions:
FACEBOOK_EXTENDED_PERMISSIONS = ['publish_stream','create_event','rsvp_event']
In the graph api explorer on facebook my request works so I know what parameters to use and, well, I am using them.
Here is my python code:
def new_event(self):
event = {}
event['name'] = name
event['privacy'] = 'OPEN'
event['start_time'] = '2011-11-04T14:42Z'
event['end_time'] = '2011-11-05T14:46Z'
self.graph.put_object("me", "events", args=None, post_args=event)
The code that is calling the facebook api is roughly: (also the access_token is added to the post_args which then is converted to post_data and urlencoded.
file = urllib.urlopen("https://graph.facebook.com/me/events?" +
urllib.urlencode(args), post_data)
The error I am getting is:
Exception Value: (#100) Invalid parameter
I am trying to figure out what is wrong, but am also curios of how to figure out overall what is wrong so I can debug this in the future. it seems to be too generic of an error because I don't know what is wrong.
Not really sure how post_args works but this call did the trick
graph.put_object("me","events",start_time="2013-11-04T14:42Z", privacy="OPEN", end_time="2013-11-05T14:46Z", name="Test Event")
The invalid parameter most likely is pointing to how you are feeding the parameters as post_args. I don't think the SDK was ever designed to feed it like this. I could be mistaken as I'm not really sure what post_args would be doing.
Another way based on how put_object is setup with **data it would be
graph.put_object("me","events", **event)

Categories