Office365-rest-python-client: Kesalahan dalam memperoleh_token_for_user

Dibuat pada 4 Des 2019  ·  11Komentar  ·  Sumber: vgrem/Office365-REST-Python-Client

Halo,

Saya mencoba menyambungkan ke portal Sharepoint intranet saya dengan Office365-REST-Python-Client, tetapi gagal saat memanggil acquire_token_for_user() dari kelas AuthenticationContext:

url = " https://perusahaansaya.sharepoint.com "
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user("nama_penggunasaya", "sandi_saya")

memicu kesalahan berikut:

AttributeError: objek 'NoneType' tidak memiliki atribut 'teks'

Salam,
tanda

question

Komentar yang paling membantu

Ini bekerja untuk saya juga. URL juga dapat berupa " https://mycompany.sharepoint.com/sites/AnotherSite " atau " https://mycompany.sharepoint.com/sites/AnotherSite/Subsite "

Coba dengan kode ini sebagai gantinya:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions

user_credentials = {
    'username' : '[email protected]',
    'password' : 'my_password'
}

site_url = "https://mycompany.sharepoint.com/"

ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_user(user_credentials['username'], user_credentials['password']):
  request = ClientRequest(ctx_auth)
  options = RequestOptions("{0}/_api/web/lists".format(site_url))
  options.set_header('Accept', 'application/json')
  options.set_header('Content-Type', 'application/json')
  data = request.execute_request_direct(options)
  s = json.loads(data.content)

Semua 11 komentar

Saya punya masalah yang sama persis

Sama, ini baru saja muncul, tidak dapat mengakses titik berbagi lagi.

Saya memiliki masalah yang sama dan tidak dapat mengakses titik berbagi perusahaan. Dalam edisi lain (#76 , pada 5 Agustus 2018) menunjukkan solusi berikutnya (yang belum berhasil untuk saya):

_Terselesaikan. Masalahnya adalah penggunaan pengguna perusahaan, yang pemeriksaannya dilakukan, hanya melalui browser, antara Azure Active Directory dan Active Direcotry internal. Untuk skrip batch, saya telah membuat pengguna di cloud AAD._

Sebenarnya, saya memiliki pengguna saya di AAD, tetapi saya masih tidak dapat mengakses :( ada solusi/petunjuk?

Kode saya berfungsi:
namapengguna = 'namapengguna saya'
kata sandi = 'kata sandi saya'
ctx_auth.acquire_token_for_user(namapengguna=namapengguna, kata sandi=passWord)

Ini bekerja untuk saya juga. URL juga dapat berupa " https://mycompany.sharepoint.com/sites/AnotherSite " atau " https://mycompany.sharepoint.com/sites/AnotherSite/Subsite "

Coba dengan kode ini sebagai gantinya:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions

user_credentials = {
    'username' : '[email protected]',
    'password' : 'my_password'
}

site_url = "https://mycompany.sharepoint.com/"

ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_user(user_credentials['username'], user_credentials['password']):
  request = ClientRequest(ctx_auth)
  options = RequestOptions("{0}/_api/web/lists".format(site_url))
  options.set_header('Accept', 'application/json')
  options.set_header('Content-Type', 'application/json')
  data = request.execute_request_direct(options)
  s = json.loads(data.content)

Masalah ini harus diperbaiki dengan PullRequest #168
Anda sekarang akan melihat pesan kesalahan yang lebih spesifik.
Kami mendapatkan kesalahan khusus ini setiap kali otentikasi gagal.

Catatan: Anda harus meningkatkan ke versi terbaru 2.1.6-1

Hai Mark, @KasperSvendsen dan @fpinab ,

hanya pembaruan kecil, karena Anda menyebutkan:

Sebenarnya, saya memiliki pengguna saya di AAD

saya yakin Anda merujuk ke Office 365 Single Sign-On untuk skenario

Kabar baiknya, dukungan untuk autentikasi gabungan berbasis SAML dengan SharePoint Online telah diperkenalkan di versi 2.1.7 , yang berarti autentikasi dengan akun pengguna Active Directory jika kita bekerja seperti yang diharapkan sekarang.

Prasyarat

Diasumsikan otentikasi multi-faktor untuk pengguna dinonaktifkan

Catatan

sejak versi baru belum dirilis ke PyPI, perlu diinstal dari GitHub bukan pada saat ini, seperti ini:

pip install git+ https://github.com/vgrem/Office365-REST-Python-Client.git

Bersulang,
Vadim

@vgrem
Saya telah memperbarui ke versi baru untuk mencoba mendukung skenario ADFS. tapi aku masih tidak bekerja.
di bawah ini adalah contoh kodenya:

from office365.runtime.auth.authentication_context import AuthenticationContext
account = "[email protected]"
password = "example"
url = "https://example.sharepoint.com/sites/base-dok-testing"

ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(account, password)

di bawah ini adalah lognya:

16/Jun/2020 10:18:15] DEBUG [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_token:acquire_token:45] acquire_token called
[16/Jun/2020 10:18:15] DEBUG [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_token:acquire_token:48] Acquiring Access Token..
[16/Jun/2020 10:18:15] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): login.microsoftonline.com:443
[16/Jun/2020 10:18:16] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://login.microsoftonline.com:443 "POST /GetUserRealm.srf HTTP/1.1" 200 1448
[16/Jun/2020 10:18:16] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): fs.kerialis.fr:443
[16/Jun/2020 10:18:20] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://fs.kerialis.fr:443 "POST /adfs/services/trust/2005/usernamemixed HTTP/1.1" 200 6542
[16/Jun/2020 10:18:20] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): login.microsoftonline.com:443
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://login.microsoftonline.com:443 "POST /rst2.srf HTTP/1.1" 200 3499
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): kerialisfr.sharepoint.com:443
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://kerialisfr.sharepoint.com:443 "HEAD /sites/base-dok-testing/_vti_bin/idcrl.svc HTTP/1.1" 401 0
[16/Jun/2020 10:18:21] ERROR [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_authentication_cookie:acquire_authentication_cookie:208] An error occurred while retrieving auth cookies from https://kerialisfr.sharepoint.com/sites/base-dok-testing/_vti_bin/idcrl.svc

@Simplici , apakah Anda yakin versi v2.1.8 atau yang lebih baru digunakan di pihak Anda?

Jika tidak, Anda mungkin akan menemukan masalah yang sama seperti yang dilaporkan di sini .

@vgrem saya menggunakan 2.1.7.post1.

saya update ke rilis terbaru 2.1.9, hasilnya sama.

rekan saya telah membuat beberapa modifikasi dan kemudian berhasil: https://github.com/vgrem/Office365-REST-Python-Client/issues/210 .

@vgrem Saya memiliki masalah yang sama. Kode di bawah ini mengembalikan kesalahan "Terjadi kesalahan saat mengambil cookie auth dari https://company.sharepoint.com/_vti_bin/idcrl.svc "

Saya telah menginstal 2.1.7.post1 juga tetapi saya tidak memiliki akses admin untuk memeriksa otentikasi multi faktor.

dari office365.runtime.auth.authentication_context impor AuthenticationContext
dari office365.sharepoint.client_context impor ClientContext
dari office365.sharepoint.file impor File

url = ' https://perusahaan.sharepoint.com '
nama pengguna = ' [email protected] '
kata sandi = 'xxx'

ctx_auth = AuthenticationContext(url)

jika ctx_auth.acquire_token_for_user(nama pengguna, kata sandi):
ctx = ClientContext(url, ctx_auth)
web = ctx.web
...

Apakah halaman ini membantu?
0 / 5 - 0 peringkat