Найти - Пользователи
Полная версия: Ошибка IndexError: string index out of range
Начало » Python для новичков » Ошибка IndexError: string index out of range
1
py_newbie
Всем привет.
Помогите пожалуйста.
если в ipython ввожу последовательно вот эти строки, то все отрабатывает и получаю данные из сервера.
 from ldap3 import Server, Connection, ALL
server = Server('172.17.1.2', get_info=ALL)
conn = Connection(server, 'imya@domen.ru', 'password')
conn.search('dc=eksmo-office,dc=ru',
              '(&(objectclass=person)(sn=Фамилия))',
              attributes=['sAMAccountName', 'mail', 'telephoneNumber', 'middleName', 'displayName', 'description'])
 print(conn.entries)

А если все это пихаю в файл скрипта
 cat adress-book.py
 #!/bin/env python
from ldap3 import Server, Connection, ALL
server = Server('172.17.1.2', get_info=ALL)
conn = Connection(server, 'imya@domen.ru', 'password')
conn.search('dc=eksmo-office,dc=ru',
              '(&(objectclass=person)(sn=Фамилия))',
              attributes=['sAMAccountName', 'mail', 'telephoneNumber', 'middleName', 'displayName', 'description'])
 print(conn.entries)

то получаю ошибку
$ ./adress-book.py
o
l
l
e
h
 Traceback (most recent call last):
  File "./adress-book.py", line 3, in <module>
    from ldap3 import Server, Connection, ALL
  File "/usr/lib/python3.5/site-packages/ldap3/__init__.py", line 321, in <module>
    from .core.server import Server
  File "/usr/lib/python3.5/site-packages/ldap3/core/server.py", line 36, in <module>
    from .tls import Tls
  File "/usr/lib/python3.5/site-packages/ldap3/core/tls.py", line 28, in <module>
    from ..utils.log import log, log_enabled, ERROR, BASIC, NETWORK
  File "/usr/lib/python3.5/site-packages/ldap3/utils/log.py", line 26, in <module>
    from logging import getLogger, getLevelName, DEBUG
  File "/usr/lib/python3.5/logging/__init__.py", line 28, in <module>
    from string import Template
  File "/home/das-ich/src/pylessons/string.py", line 4, in <module>
    letter = string[index]
IndexError: string index out of range

Научите как это правильно в скрипт написать?

FishHook
py_newbie
Скажите, вы долго изучали трейсбэк?
Вот эта строка вам совсем-совсем ничего не напоминает?
 letter = string[index]
И файла “/home/das-ich/src/pylessons/string.py” у вас в проекте нет?
py_newbie
Спасибо что пнули. но только мне не понятно почему данный скрипт трогал другие файлы в папке.
перенес в другую папку и все отработало.
FishHook
py_newbie
мне не понятно почему данный скрипт трогал другие файлы в папке
Потому что в стандартной библиотеке третьего питона есть модуль string. Никогда не называйте свои переменные стандартными зарезервированными идентификаторами типа list, dict, str, string, filter, map, file и так далее, чтобы не получать таких вот эксцессов.
py_newbie
Спасибо большое за подсказку. учту.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB