Hello @dan ,
I tried exactly as you said but the problem still persists. Here it is the changed script. I added the registration section with my application id and also changed the factor to 1 "factor": 1
from fusionauth.fusionauth_client import FusionAuthClient
import math
from dal import DAL
from migration_parameters import MigrationParameters
from reconsile_users import reconcile_users
from user import User
try:
# Parse command line arguments
migration_parameter = MigrationParameters()
fa_client = FusionAuthClient(migration_parameter.fusion_auth_api_key, migration_parameter.fusion_auth_base_url)
total_number_of_records = -1
# Get total number of users in db
db = DAL(configuration=migration_parameter)
result = db.get_single("Select count(*) from users "
"where migrated <> 1 OR migrated IS NULL")
total_number_of_records = result[0]
total_number_of_db_chunks = math.ceil(total_number_of_records / migration_parameter.db_chunk_size)
for db_index in range(0, total_number_of_records, migration_parameter.db_chunk_size):
current_db_chunk = db.get(
"SELECT id, birthdate, age, username, anon_url, `type`, subtype, lock_type, messages_unread, salt, "
"password, email, "
"first_name, middle_name, last_name, phone_number, timezone_id, `_timezone_id`, street_address,"
"city_address, city_id, state_address, state_id, zip_code, country, lastupdate, active,"
"gender, birthday_input, contact_pref_manage, subscription, subscription_start, subscription_expires FROM "
"users where migrated <> 1 OR migrated IS NULL"
, db_index, migration_parameter.db_chunk_size)
total_number_of_chunk_records = len(current_db_chunk)
total_number_of_fa_chunks = math.ceil(total_number_of_chunk_records / migration_parameter.fa_chunk_size)
for fa_index in range(0, total_number_of_chunk_records, migration_parameter.fa_chunk_size):
current_fa_chunk = current_db_chunk[fa_index:fa_index + migration_parameter.fa_chunk_size]
template_request = {
'sendSetPasswordEmail': False,
'skipVerification': True,
"users": []
}
import_successfully_user = []
import_successfully = []
# Prepare request
for el in current_fa_chunk:
try:
user = User.parse(result=el)
template_request['users'].append({
'sendSetPasswordEmail': False,
'skipVerification': True,
"active": True,
"birthDate": user.birthdate,
"data": {
"displayName": user.first_name + " " + user.last_name
},
"email": user.email,
"encryptionScheme": "gyo-password-encryptor",
"expiry": 1571786483322,
"factor": 1,
"firstName": user.first_name,
"fullName": user.first_name + " " + user.middle_name + " " + user.last_name,
"imageUrl": "http://65.media.tumblr.com/tumblr_l7dbl0MHbU1qz50x3o1_500.png",
"insertInstant": 1331449200000,
"lastName": user.last_name,
"middleName": user.middle_name,
"password": user.password,
"passwordChangeRequired": False,
"preferredLanguages": [
"en"
],
"salt": user.salt,
"timezone": "America/Denver",
"twoFactorEnabled": False,
"usernameStatus": "ACTIVE",
"username": user.username,
"verified": True,
"registration": [
{
"applicationId": "74e5f2cc-b485-47d5-94d7-8854747edd82"
}
]
})
import_successfully.append(str(el[0]))
import_successfully_user.append(str(el[3]))
except Exception as exx:
print('Failed to process user with ID: ', el[0], ' with error: ', exx.args)
fa_response = fa_client.import_users(template_request)
if fa_response.response.status_code == 200:
# everything is ok
db.update_all("update users set migrated = 1 where id = %s ",
[(record,) for record in import_successfully])
reconcile_users(migration_parameter, import_successfully_user)
elif fa_response.response.status_code == 400 and 'unique' in fa_response.error_response['generalErrors'][0][
'message']:
# users are already imported on fusion auth but for some reasons are not stored on the db
db.update_all("update users set migrated = 1 where id = %s ", import_successfully)
reconcile_users(migration_parameter, import_successfully_user)
else:
print('Failed to import users with starting ID: ', current_fa_chunk[0][0], ' ending ID: ',
current_fa_chunk[::len(current_fa_chunk) - 1][1][0])
template_request['users'].clear()
except Exception as ex:
print(ex)