CMIS PermissionDeniedException - python

I'm trying to get service(SAP mobile document) via CMIS.
In service web client i can create folder and add file.
Via CMIS I can auth and get repo's list, but that's all.
For other methods I get cmislib.exceptions.PermissionDeniedException: Error 403
I used this doca http://chemistry.apache.org/python/docs/
from cmislib import *
client = CmisClient('https://service/mcm/b/atom', 'user', 'pwd')
print client.getRepositories()
#REPO
#repo = client.defaultRepository
repo = client.getRepository('573f7fc4-2c76-49a2-b63c-d39e370edfde')
print repo.name
#FOLDER
rFolder = repo.rootFolder
print rFolder.id
#denied
#rFolder.getChildren()
#acl = rFolder.getACL()
#print rFolder.getName()
#newFolder = rFolder.createFolder('testfolder')
denied returns
cmislib.exceptions.PermissionDeniedException: Error 403 at https://url/mcm/b/atom/573f7fc4-2c76-49a2-b63c-d39e370edfde/id?id=906f3ae3-a4c9-3210-7292-c840e0cff769&filter=&includeAllowableActions=false&includeACL=false&includePolicyIds=false&includeRelationships=&renditionFilter=
*the same error for default repo
#repo = client.defaultRepository

SAP Mobile Documents requires cookies. Turn cookies on on the client side and those exceptions will disappear.
See http://help.sap.com/saphelp_mdocs10/helpdata/en/0e/432781e0c646a09602a4aab786734d/content.htm?frameset=/en/d5/476115e8264a33a52fd59d260892cb/frameset.htm&current_toc=/en/69/ec44f07b34409a8b65005f51315f1a/plain.htm&node_id=105 how to the authentication works.

Related

How to Send a URL Link within the Text Body with the Twilio API using Python

I am trying to send a text message that contains both text and a hypeprlink but am encountering the following message from the Twilio API:
"Error - 12300 Invalid Content-Type: Attempt to retrieve MediaUrl returned an unsupported Content-Type."
Here is the code I am attempting to leverage:
import os
from twilio.rest import Client
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
message = client.messages \
.create(
body='Article: https://4r7s.short.gy/GPaoh7',
from_='123-345-5667',
to='123-345-5668',
)
When I send a message without a hyperlink it works fine (e.g. body = 'Here is the article for you to read') but when it contains a link I receive the aforementioned error. I've also tried using a shortened url of the above but that causes the same issue.
I was just able to send messages containing that exact link using my own Twilio account.
There might be an issue in that you are using phone numbers in local format, when they should be provided in e.164 format.
It's possible that your message is being blocked. Certain carriers don't like when you use link shorteners to obscure a link.
The error you are getting definitely seems weird, since you are not sending media. If you continue to have issues with this, I would contact Twilio support.

On accessing Files using O360 library : Client Error: 403 Client Error: Forbidden for url

I am trying to access the files in my one drive, here in python. So my code is as follow:
account = Account(credentials=credentials)
storage = account.storage() # here we get the storage instance that handles all the storage options.
# list all the drives:
drives = storage.get_drives()
# get the default drive
my_drive = storage.get_default_drive() # or get_drive('drive-id')
# get some folders:
root_folder = my_drive.get_root_folder()
attachments_folder = my_drive.get_special_folder('attachments')
# iterate over the first 25 items on the root folder
for item in root_folder.get_items(limit=25):
if item.is_folder:
print(list(item.get_items(2))) # print the first to element on this folder.
elif item.is_file:
if item.is_photo:
print(item.camera_model) # print some metadata of this photo
elif item.is_image:
print(item.dimensions) # print the image dimensions
else:
# regular file:
print(item.mime_type) # print the mime type
It throws this error: Client Error: 403 Client Error: Forbidden for url: https://graph.microsoft.com/v1.0/me/drive/special/attachments | Error Message: Access denied
I need help here, as you can see in the attached screenshot, I have defined the correct scopes as well.
Have also checked similar articles but didn't find any luck.
Resource: https://pypi.org/project/O365/#onedrive
Thanks.
Modify the scopes to : scopes=['basic', 'message_all', 'openid', 'email', 'profile', 'offline_access', 'onedrive', 'onedriveall']

How to successfully receive Google Drive v3 Push Notifications using python?

I have completed the steps provided by Google to implement push notifications using the Drive API. Everything goes as described except I do not receive any notifications from Google whenever a change occurs (listed as Step 4 below).
Below is a summary of the steps I followed and the results at each stage:
Step 1 (Success): Verify that you own the domain
I went to Search Console as directed and successfully verified the site.
Step 2 (Success): Register your domain
I visited the Domain Verification page and added my domain in the API Console. Google API Console updated to show the list with my desired domain.
I have a valid SSL certificate from GoDaddy for my domain and have verified that as well.
Step 3 (Success): Created my notification channel
Using the python SDK, I created the channel and got back a response from Google. The python code below shows how I did this. Note: The address included in my request directs Google to send notifications to my Flask website that I am hosting in Google's App Engine. I am showing the domain as my_domain.com here for privacy as I am in the process of bringing up the site.
channel_id = str(uuid.uuid4())
body = {
'kind': 'api#channel',
'id': channel_id,
'type': 'web_hook',
'address': "https://my_domain.com/notifications"
}
try:
start_page_token = service.changes().getStartPageToken().execute().get('startPageToken');
print(service.changes().watch(pageToken=start_page_token, body=body).execute())
except Exception as e:
print('Exception: {}'.format(e))
And here is the response from Google:
{u'resourceId': u'vTMwJWl7a23Af1LK1TpJZ38eO_0', u'kind': u'api#channel', u'expiration': u'1538433975000', u'id': u'dce14225-95c8-42a7-9945-4fed1604c848', u'resourceUri': u'https://www.googleapis.com/drive/v3/changes?alt=json&includeCorpusRemovals=false&includeRemoved=true&includeTeamDriveItems=false&pageSize=100&pageToken=4919&restrictToMyDrive=false&spaces=drive&supportsTeamDrives=false&alt=json'}
Step 4 (Failed): Process a notification from Google
I am running a Flask website on App Engine and created an app.route to receive notifications from Google. I've included the code below. I never receive anything at this URL.
#app.route('/notifications')
def notifications():
print('in notifications()')
try:
chan_id = request.args.get('X-Goog-Channel-ID', 'empty')
msg_num = request.args.get('X-Goog-Message-Number', 'empty')
rid = request.args.get('X-Goog-Resource-ID', 'empty')
state = request.args.get('X-Goog-Resource-State', 'empty')
resource_uri = request.args.get('X-Goog-Resource-URI', 'empty')
goog_changed = request.args.get('X-Goog-Changed', 'empty')
goog_chan_exp = request.args.get('X-Goog-Channel-Expiration', 'empty')
goog_chan_token = request.args.get('X-Goog-Channel-Token', 'empty')
print('chan_id: {}'.format(chan_id))
print('msg_num: {}'.format(msg_num))
print('rid: {}'.format(rid))
print('state: {}'.format(state))
print('resource_uri: {}'.format(resource_uri))
print('goog_changed: {}'.format(goog_changed))
print('goog_chan_exp: {}'.format(goog_chan_exp))
print('goog_chan_token: {}'.format(goog_chan_token))
except Exception as e:
print('notifications() exception: {}'.format(e))
print('leaving notifications()')
return jsonify(result='done')
I'm not sure if this is the problem but, when I tried Google Drive push notifications, I didn't use the SDK. I only made a POST request as it shows in the documentation.
Could you try to make a POST request to "https://www.googleapis.com/drive/v3/changes/watch" instead of using service.changes().watch()?
You will need an access_token for the request, but I believe you wont need to send a startPageToken as they don't use it in their example:
I hope it helps!

how can i update an alfresco share site?

I am trying to update a website (just change its name) I have created with the Share script in Alfresco, but I am getting a 401 response. I'm sure my login and password are correct.
Code:
s = requests.Session()
data = {'username':"admin", 'password':"admin"}
url = "http://127.0.0.1:8080/share/page/dologin"
r = s.post(url, data=data)
if (r.status_code != 200) :
print "Incorrect login or password "
url1 = "http://127.0.0.1:8080/alfresco/service/api/sites/OdooSite50"
print url_alfresco
jsonString = JSONEncoder().encode({
"title" : name
})
headers = {'content-type': 'application/json',"Accept":"application/json"}
site = s.put(url1,headers=headers,data=data)
if (site.status_code != 200) :
print " Error while creating site"
print site.status_code
I am getting the error on the second part. The login part works without any problems.
Can you tell me what I do wrong?
This is because you are using different contexts to make your queries.
The Alfresco stack is made of multiples parts :
alfresco.war
share.war
solr.war
If we forget the solr part and focus on your problem, you have :
a content repository (alfresco) which contains the core services of alfresco
a web application (share) which contains the web ui of your application and communicate the content repository to do some actions
They don't share the same context and have different lives. One can be on a server, the other one can be in another one server.
So this mean, when you are authenticating, you are doing it on the share context :
http://127.0.0.1:8080/share/page/dologin
and when you are trying to update your website, you are doing it on the alfresco context (on which you are not authenticated yet) :
http://127.0.0.1:8080/alfresco/service/api/sites/OdooSite50
I see two solutions then :
You do your authentication on the alfresco context (webservice alfresco/s/api/login) and then you will be authenticated for calling your alfresco site services
You pass through the share proxy : /alfresco/service/api/sites becomes /share/proxy/alfresco/api/sites

Instagram API using Python

I am currently using Instagram API in the sandbox mode using Python's python-instagram library. Now, I have an application and its associated client id, client secret and access token, and one connected sandbox user.
Earlier today, I was experimenting with the users/search endpoint. First, I directly used their endpoint URL to send a request:
https://api.instagram.com/v1/users/search?q=XXXX&access_token=<my_access_token>
where XXXX is the connected sandbox user of my Instagram application. This is the generated response:
{"meta":{"code":200},"data":[{"username":"XXXX","bio":"Twitter: #XXXX","website":"","profile_picture":"https:a.jpg","full_name":"XXXX XXXX","id":"22222222"}]}
Now, I tried using the python-instagram library to send request to the same endpoint as follows:
from instagram.client import InstagramAPI
access_token = <my_access_token>
api = InstagramAPI(client_secret='aaaa', access_token = access_token[0])
usr = api.user_search('XXXX')
print usr
However, this is the response I get in this case:
[User: XXXX]
Why is it that I get different responses when I try to call the same endpoint using the direct URL and the Python library?
What python-instagram is doing is that it will take the raw JSON response you get when you issue an HTTP request, and map it to python objects.
When you issue a print usr, you are printing a User object that's in a list, so you see a string which is [User: XXXX].
You can find the model they use for the User object here. It actually directly maps the fields from the Json to get attributes.
Try the following code to retrieve a username and id:
my_usr = usr[0]
print 'User id is', my_usr.id, 'and name is ', my_usr.username

Categories