Python Forum
I am getting an Error, and not sure why? My goal is to print out
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am getting an Error, and not sure why? My goal is to print out
#1
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.
Reply
#2
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()
Reply
#3
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
Reply
#4
Could you paste your code with
code tags
please and some of the contents of 'file6.txt'.
Reply
#5
contents of file6.txt
root@Raj:~/ali# cat file6.txt
test-user
ram
kumar
raj
Reply
#6
Ok - what data type is 'i' supposed to be?
Int? String?
And do you get any errors?
Reply
#7
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.
Reply
#8
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting a valueError. And not sure why? My goal is to visualize the correlation ReadytoCode 0 477 Dec-11-2023, 05:33 AM
Last Post: ReadytoCode
  Goal Seek tdutcher05 1 790 Nov-17-2023, 10:33 PM
Last Post: deanhystad
  I get an FileNotFouerror while try to open(file,"rt"). My goal is to replace str decoded 1 1,410 May-06-2022, 01:44 PM
Last Post: Larz60+
  Print Error DaveG 1 1,095 Apr-07-2022, 03:10 AM
Last Post: deanhystad
  Error with print and return commands TheDark_Knight 2 1,941 Jan-15-2020, 04:59 PM
Last Post: TheDark_Knight
  Error in print statment leodavinci1990 1 1,937 Jul-21-2019, 04:46 AM
Last Post: buran
  Why do i have invalid syntax on a line after print, i see no error ? iofhua 5 2,938 May-24-2019, 05:42 PM
Last Post: Yoriz
  Need help with print error newbiepy 2 2,097 Apr-22-2019, 08:00 PM
Last Post: Yoriz
  Turning Robot towards goal, comparison of angles SpaceTime 0 2,762 Jan-21-2019, 10:26 PM
Last Post: SpaceTime
  Attribute error print statement error jamshaid1997 1 2,465 Jan-20-2019, 04:02 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020