Pubnub Access Management with Python - python

I am trying to use Pubnub Access Management with Python by I always get an error message saying that the 'Signature Does not Match'. I know their documentation says that this means that the Secret/Publish/Subscribe keys may be wrong but I have triple checked that they are correct. Also checked in Pubnub developer console and it works fine from there.
Here is the method that I am using:
def get_pubnub_token(request, connector_id):
pubnub = Pubnub(settings.PUBKEY, settings.SUBKEY, secret_key=settings.PUB_SECRET_KEY)
authkey = str(uuid.uuid4())
result = pubnub.grant(channel=connector_id+"-pnpres", auth_key=authkey, read=True, write=True, ttl=60)
if result['error']:
return HttpResponse(status=result['status'])
result = pubnub.grant(channel=connector_id, auth_key=authkey, read=True, write=True, ttl=60)
if result['error']:
return HttpResponse(status=result['status'])
result = pubnub.grant(channel=connector_id+"-stream", auth_key=authkey, read=True, write=True, ttl=60)
if result['error']:
return HttpResponse(status=result['status'])
jsonstr = get_json(authkey)
return HttpResponse(jsonstr, content_type='application/json')
I wonder if anyone has done this before and if they could give me any tips as to why I could be seeing this error.

Which version of the SDK are you on?
Also, this may also happen because your system clock is not set to NTP. Can you verify its set to NTP, and try again?
If it persists, please contact us at support#pubnub.com and we'd be happy to help trace the issue down with you.
geremy

There were problems using version 3.7.1 of the SDK in python 3.4.3. They were addressed by Pubnub's developers some time last night and it seems to have been resolved in their development code. I guess they will put it into the production code some time in the near future.

Related

`undetected_chromedriver` silently fails

I'm using a pretty standard boilerplate undetected_chromedriver installation:
LOCAL_CHRPATH = '/opt/google/chrome/chromedriver'
driver = uc.Chrome(
driver_executable_path=LOCAL_CHRPATH, headless=True
)
However, driver.get(url) simply fails silently, exiting the program. I have looked through the documentation, and found no way to get diagnostics pre or post get. Any idea of what to do or where to check?
You can pretty much ignore the specifics about the path and so on; the real question here is to understand why it fails.
Update: if I set debug to True, I get the same error that's indicated in this SO question. However, don't see a workaround for that. As an indication, this was working correctly with Python 3.10, stopped working when downgrading to 3.9
LOCAL_CHRPATH = '/opt/google/chrome/chromedriver'
This is local variable, not environmental. To set envvar you could:
os.environ["LOCAL_CHRPATH"] = '/opt/google/chrome/chromedriver'
Or just don't use envvars, or set default value:
driver = uc.Chrome(
driver_executable_path=os.getenv('LOCAL_CHRPATH', LOCAL_CHRPATH),
headless=True
)

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