0

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?

forvas
  • 9,801
  • 7
  • 62
  • 158
  • Seems that you are authenticating a different context (/share) than the one you are doing a request (/alfresco). What is happening if you authenticate on the backend alfresco, or call the /alfresco/service/api/sites by using the share proxy /share/proxy/alfresco/api/sites ? – Akah Aug 02 '16 at 09:12
  • thx for your answer , i typed in the navigator url "http://127.0.0.1:8080/share/proxy/alfresco/api/sites" i got the list of existing sites on alfresco with details and the same with "http://127.0.0.1:8080/alfresco/service/api/sites" and i got to enter the login and password – yosri slama Aug 02 '16 at 10:49
  • Yes, because your alfresco has two contexts. I'm gonna write an answer, it will be more clear. – Akah Aug 02 '16 at 11:17

1 Answers1

2

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 :

  1. 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
  2. You pass through the share proxy : /alfresco/service/api/sites becomes /share/proxy/alfresco/api/sites
Akah
  • 1,890
  • 20
  • 28
  • thx for your answer i understand now the difference but i still have the same problem with the content repository (alfresco) i have a 400 responce :bad request in the authenntification process and with the share one i have the same problem with 401 responce . is the url the same ? "/alfresco/service/api/sites" – yosri slama Aug 02 '16 at 12:35
  • 1
    400 means that your badly formatted your login query. Look at your script definition to see if something is not missing : http://localhost:8080/alfresco/s/script/org/alfresco/repository/login.post. For the second, I did a mistake, I corrected it in my answer. – Akah Aug 02 '16 at 12:58