Unsupported operand type error

I am getting this weird error in my code and I was hoping someone may be able to help.

 

When writing my Webisode channel, I wanted to have all the different locations you might pull webisodes from including YouTube.  Rather than rewrite the YouTube code that already works, I just copied its Parsefeed function into my channel. (I made note of the fact in the code's comments). The only difference in my code and the original YouTube Code is the base url used, since you do not log in or have a username and password in my version.

 

Anyway, I wanted to add the YouTube's channels ability to pull more than 50 videos, by splitting it into separate pages. but when I try to add that section to my code and then add a show that has more than 50 results and try to click on the second page, I get the following error:

    local_url += '&start-index=' + str((page - 1) * MAXRESULTS + 1)
TypeError: unsupported operand type(s) for -: 'str' and 'int'

But it seems by the error message above that the issue is either with my parenthesis or that it is saying that "page" is a string and not an integer. Also, it doesn't have a problem with this line on the first run through, only when it gets to page 2 does it produce this error.

 

Since I pretty much just copied and pasted the YouTube code into my channel and it works in the YouTube channel, I cannot understand why am I getting this error.

 

Any help is appreciated. And if you would need to see any code, just let me know what you need to see. (Since it is not working right now, I just have this additional page coding in a local test version on my computer)

I figured out the issue here. On the second run through the function, the value of "page" became a string, so I had to add a line to my code right before the line that gave the error above to convert the value of the "page" variable to an integer.

What I do not get is why I had to do this and the YouTube channel did not. I copied all the code that included the "page" variable line for line from the YouTube channel. Not one line is different, except that I send one additional argument to the function.

When using the @route decorator you can set page to be an int (assuming you're passing it into a function).  By default anything done on a route that's not explicitly set defaults to a string AFAIK.

See example here: https://github.com/Gerk/Dailymotion.bundle/blob/master/Contents/Code/__init__.py#L59

 

@route("/video/dailymotion/getvideolist", page=int, limit=int)

That was it!  I had added routes to all of my functions, but the YouTube channel didn't have any routes that is why it continued to return a string for page the second time through my function.  That is very good to know.  Thank you so much for that info. That will save me from a lot of confusion and frustration in the future.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.