samedi 1 avril 2023

need some solution"bytes or str expected error"

There is a problem that I can't solve.. I'm a student and don't know many solutions

this is my code:

from telethon.sync import TelegramClient
from telethon.sessions import StringSession
from telethon import functions, types
from keep_alive import keep_alive
import asyncio
import os
import time
import fileinput
import random
import csv
from telethon import errors
from telethon.sync import TelegramClient


api_id = input("API ID: ")
api_hash = input("API HASH: ")
correct_channel = input("CORRECT CHANNEL: ")


ses_string = os.getenv('ses_string')
    
keep_alive()

starting_points = [random.randint(0, 5) for i in range(3)]
read_nbr_of_lines = 2

for sp in starting_points:
    print('random starting line: %s'%sp)
    read_lines = 0
    with open('username.csv') as cf:
        lines = csv.reader(cf)
        for nbr, line in enumerate(lines):
            if nbr < sp - 1: continue
            read_lines += 1
            if read_lines > read_nbr_of_lines: break
            print(nbr, line)
          
print('A randomly selected username is:', lines)

with TelegramClient(StringSession(ses_string), api_id, api_hash) as client:
    while True:
        try:
            time.sleep(10)
            result = client(functions.channels.UpdateUsernameRequest(
               channel= correct_channel ,
               username = starting_points
            ))
        except Exception as e:
            print(type(e), str(e))

I want the code to pick from my CSV file either randomly or in a running and repeating order one row and insert it into username = ???????????




Aucun commentaire:

Enregistrer un commentaire