발생한 오류
Traceback (most recent call last):
File "user-data.py", line 32, in <module>
email = fake.unique.ascii_free_email()
File "C:\Users\21528463\AppData\Local\Programs\Python\Python36\lib\site-packages\faker\proxy.py", line 320, in wrapper
raise UniquenessException(f"Got duplicated values after {_UNIQUE_ATTEMPTS:,} iterations.")
faker.exceptions.UniquenessException: Got duplicated values after 1,000 iterations.
오류가 발생한 코드
from faker import Faker
from faker.providers import DynamicProvider
import time
fake = Faker('ko_KR')
class User:
"""
User Class
"""
def __init__(self, id, email, role):
self.user_id = id
self.email = email
self.role = role
def __str__(self):
return 'User(id={0}, email={1}, role={2})'.format(self.user_id, self.email, self.role)
user_role_provider = DynamicProvider(
provider_name="set_user_role",
elements=["ADMIN", "USER"],
)
fake.add_provider(user_role_provider)
user_list = []
start = time.time()
for i in range(1, 10000000):
email = fake.unique.ascii_free_email()
role = fake.set_user_role()
user = User(i,email, role)
user_list.append(user)
print("time :", time.time() - start) # 현재시각 - 시작시간 = 실행 시간
print("User 객체 생성 완료!") # 1000만 개
fake.unique.ascii_free_email()
에 unique가 들어간다. 하지만 지금 1000만개를 돌다보니 fake.unique.ascii_free_email()
에 더 이상 유니크한 값이 없어서 나는 에러인 것 같다.