When I run the code, it likes the image, but then when it comes to commenting, there is an error and the code ends.
This is the error:
Traceback (most recent call last):
File "quickstart.py", line 7, in
.like_by_tags(['isetups'], amount=30) \
File "C:\Users\Bav\Downloads\InstaPy-master\instapy\instapy.py", line 415, in like_by_tags
commented += comment_image(self.browser, comments)
File "C:\Users\Bav\Downloads\InstaPy-master\instapy\comment_util.py", line 17, in comment_image
browser.execute_script("arguments[0].value = '" + rand_comment + " ';", comment_input[0]);
IndexError: list index out of range
@atomhax
@timgrossmann I'll get to this sometime today. To me... the error "IndexError: list index out of range" is referring to the comment_input array being empty. I bet a simple try-catch-exception block is exactly what we need here. I could be wrong.
I am also having this exact same issue. (on Windows)
It seems that the comment has changed from input to textarea
I'm modifying the following line of comment_util.py
comment_input = browser.find_elements_by_xpath('//input[@placeholder = "Add a comment…"]')
To
comment_input = browser.find_elements_by_xpath('//textarea[@placeholder = "Add a comment…"]')
It's still input for me. I seem to remember that they roll out UI features
to user accounts slowly. We may have to support both versions for a while.
On Tue, May 30, 2017 at 3:26 PM, André Roggeri Campos <
[email protected]> wrote:
It seems that the comment has changed from input to textarea
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/timgrossmann/InstaPy/issues/287#issuecomment-305026687,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACv_hQn0kgiKjbMzm5PMHifnSqjGQLhuks5r_JepgaJpZM4NprB-
.
@andreroggeri we need something like what they did during the graphql changes. You can acutally see an example of it in the live code in the like_util.
But I digress.. what we need is like this I think:
comment_input = browser.find_elements_by_xpath('//input[@placeholder = "Add a comment…"]')
if comment_input:
#if comment_input is the old way do stuff
else:
comment_input = browser.find_elements_by_xpath('//textarea[@placeholder = "Add a comment…"]')
#it's the new way do more stuff
Ok, I can make a PR.
But I'm getting another error:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2017.1.1\helpers\pydev\pydevd.py", line 1585, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm 2017.1.1\helpers\pydev\pydevd.py", line 1015, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2017.1.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:/Projetos/InstaPy/quickstart.py", line 19, in <module>
.like_by_tags(like_tags, amount=100) \
File "E:/Projetos/InstaPy\instapy\instapy.py", line 415, in like_by_tags
commented += comment_image(self.browser, comments)
File "E:/Projetos/InstaPy\instapy\comment_util.py", line 22, in comment_image
print("--> Commented: " + rand_comment.encode('utf-8'))
TypeError: Can't convert 'bytes' object to str implicitly
Is not possible to concatenate a string with bytes
Whats your Python version? I just read it can make a difference how this case is handled. I ask because this line of code works fine on my Linux and MacOS builds.
I'm also having this issue on Mac OS X Python 2.7.13 I literally know no python so looks like i'm gonna have to learn 🤣
@atomhax I'm on 3.5.1 (But also checked on 3.6.1) runnin on Windows 10
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> encoded = 'Encode this'.encode('utf-8')
>>> print('Hey...')
Hey...
>>> print('Hey...' + encoded)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str, not bytes
>>>
Changing to print("--> Commented: {}".format(rand_comment.encode('utf-8'))) fixes.
I can make the PR, but will conflict with yours #288 .
So, maybe its better to make this change on your PR. What do you think about it ?
Ok. I'll make the change. 2 seconds. I want to make sure to test it first. I'm sure this is causing a lot of people a headache today.
Great ! 😄
Some tests would be great for preventing regressions, but I didn't find any. 😢
Yeah some tests are a great idea!! 👍
If you have experience writing regression tests feel free to dive in. I put that PR up. I tested it on my insta and it worked fine.
@madebybav @timgrossmann I believe PR #288 addressed this issue. Can we close it?