Python Forum

Full Version: I am getting an Error, and not sure why? My goal is to print out
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I want to call variable inside request.set_UserName(i)
but it is not happening.

with open('file6.txt')as inf:   --> i have list of username inside file6.txt
    for i in inf:
      request.set_UserName(i)  --> calling (i)variable here which is not happening getting error.
      response = client.do_action_with_exception(request)
      print(str(response, encoding='utf-8'))
Error:EntityNotExist.User The user does not exist.
You are never reading the lines of the file.
type(inf) is <class '_io.TextIOWrapper'>.
You can't loop through that - you need to read the lines first:
lines = inf.readlines()
Hi,

I can able to print the lines with below format but i am calling the variable inside request.setUserName("i")

which is not happening:

it works with this :
with open('file6.txt')as inf:
# lines = inf.readlines()
# print(lines)
for i in inf:
print(i)

Not working with this:
with open('file6.txt')as inf:
for i in inf:
request.set_UserName(i) --> (i) is not reffering to a inf.

how to refer (i) as my user's names
Could you paste your code with
code tags
please and some of the contents of 'file6.txt'.
contents of file6.txt
root@Raj:~/ali# cat file6.txt
test-user
ram
kumar
raj
Ok - what data type is 'i' supposed to be?
Int? String?
And do you get any errors?
Hi,

It's string getting an error that username is not valid.

actually "request.set_UserName("ram") " --> it has to be like this to get output.

I am maintaining the list of users in a file to run but not happening.
It should work may need to strip of new line.
with open('file6.txt') as f:
    for user in f:
        print(user.strip())
Output:
test-user ram kumar raj
What method is request.set_UserName(i) do you use Requests?