i am trying to make a disord bot send images from reddit with this code (just to grab not to send)
def random_post(subreddit):
while True:
post = reddit.subreddit(subreddit).random()
if not post.stickied:
return post
it normally works fine but every once in a while i get this error
AttributeError: 'NoneType' object has no attribute 'stickied'
it only happens with certain subreddits.
This is a known issue on Reddit's end.
Some subreddits will refuse to give you a random submission. See praw-dev/praw#885 on GitHub.
On that issue, I went in depth about the cause. My findings were: When a subreddit's moderators uncheck the "allow this subreddit to be exposed to users in /r/all, /r/popular, default, and trending lists" checkbox in their subreddit settings, it prevents the subreddit from being able to provide a random submission. For example, at the time of this writing, https://reddit.com/r/wallpapers/random just redirects to https://www.reddit.com/r/wallpapers/ instead of to some submission.
In my personal opinion, this is a Reddit bug caused by confusion between /r/random (which redirects to a random subreddit) and /r/{subreddit}/random (which redirects to a random submission within a subreddit). As it stands, the checkbox affects both settings, when in my view it only makes sense for it to affect /r/random.
In the same GitHub issue, a Reddit developer chimed in to confirm that "the two behaviors are connected" and said that this behavior "isn't a bug per se." That was over two years ago and nothing has changed on Reddit's end since.
So what does this mean for you?
Unfortunately there's no good way to get around this. As you've discovered, for some subreddits, subreddit.random() returns None. This is noted in the documentation of the method. In your code, you should check that post is not None. In the case that it is None, it's up to you how to handle that. You could just return None, or perhaps you could use an alternate method to get a random submission, such as (for instance) getting 25 submissions from the hot listing and using random.choice() to select one.
Related
I created a very simple agent on dialogflow. Every now and then, even using static responses (where only the session ID changes), the application crashes (both on Google Assistant and in the simulator).
On the logs I find the message in question: "MalformedResponse at expected_inputs [0]: Responses must provide at least one possible if this is not the final response. What does it mean?".
I don't understand what it means.
Could anyone help me?
I'm having the same problem. That i've noted is that this problem doesn't ocurre every time. The behavior is really unstable.
I'm using 2 required parameters in the intent. I don't know if that has something to do with the problem.
MalformedResponse at expected_inputs[0].input_prompt: 'input_prompt' is empty
MalformedResponse at expected_inputs[0]: Responses must provide at least one possible intent if this is not the final response
The problem, appears to be caused when you use own parameters, not when use sys. parameters.
Google answer me the following:
"Hi Alberto,
This issue has already been escalated to our engineering team. You are correct about required parameters causing the problem. Our engineering team is working thoroughly to resolve this since it is affecting some other AoG projects as well. "
I was facing the exact same issue when I was using custom entities as input parameters to my action.
I was asking for 2 custom parameters and one system (sys.color) and triggering the same with input prompts.
I found a workaround for that by taking all 3 in separate intents and using the response of the previous intent as a trigger to enter the next parameter, also by making the training phrases as sample values of the custom parameter.
I am still in contact with Dialogflow Suppport and waiting for bug fix but it works for now.
I'm wiring a Chrome extension which needs to be able to detect whenever a thread on 4chan has been updated (threads autoupdate). I've tried using a MutationObserver, but it is being set off too many times (4chan thread pages change often for a variety of reasons outside of new posts, including hovering over/expanding images, viewing post replies, opening the reply dialog, etc.)
I'm at work, so I can't visit 4chan to help you more specifically :^)
But, you should find out the distinguishing class or attribute of each post, e.g. by using Chrome's Inspect, store the last post ID (i.e. the dubs, trips, quads-meter), and on each mutation event, check if the last post ID matches the previous post ID, to determine whether there has been new posts.
There is probably a more efficient way to detect only posts, but this should do the job just fine, if you're already familiar with MutationObserver.
Since a few days ago we've been getting an error response from Instagram API - it complains that we are using an invalid cursor 'min_id' when accessing the Tags endpoint.
Thing is we don't use 'min_id'. We use 'min_tag_id', which according to the documentation (deprecated & current) is a valid cursor for this endpoint.
Doing some research I see that some people have been getting unexpected errors too (though different ones) around this week.
Example API request (plug an access token and paste in a browser to see for yourselves):
https://api.instagram.com/v1/tags/nofilter/media/recent?access_token=<ACCESS_TOKEN>&min_tag_id=AQCvuinNA31T_hoSa-RaCsQigBknfYaBv2_VcCn1kp4MX5whyr7v7AfpOzio8E4lcQ9TZIKZbN_ZAqEmuzmslq8qMmFTQF-1ocNntqDIjlN4va4GxocNeBxmo29nXEOjKIRVvce5PuvoXk3MY9nuNd6hbxFj7TW_FEWTWpdx9FNzEQ
And the response:
{"meta":{"error_type":"APIInvalidParametersError","code":400,"error_message":"min_id is not a valid cursor for this tag."}}
Any idea?
I got this response from Instagram when enquiring about invalid pagination tokens
"Thanks for the report. We are aware of this issue and it happens when
pictures are un-tagged (e.g. The comment with the tag is deleted). We
are working on a fix but I don’t have an eta to share at the moment."
OK, so this is how I solved it - after waiting for a few days and seeing that nothing happens then I have deleted all min_tag_id values that I have in store. I also altered my app logic to deal with the situation (in my case when there's no min_tag_id then I load some historical posts, which I commented out for this fix).
I ran the import process and this repopulated the min_tag_id field. The new values have no problems. Either they fixed the issue or the un-tagging thing didn't happen to me again yet.
So far so good. Will post updates if any.
I have some serious problems testing a sharepoint site with selenium/bromine. As I did't find an answer via various searches I hope someone here can point me in the right direction.
I am constantly getting timeouts opening the main page, but the server is definetly fast enough to answer the request and at 90% idle. Nevertheless I just get logs like these:
open http://username:passwd#10.13.110.54/default.aspx | Timed out after 90000ms
Test terminated The selenium server did not return OK
The auth popup is popping up at irregular intervals (every 5 to 10 clicks) although every open command uses the http://username:passwd#10.13.110.54/ as prefix
Clicking on elements is sometimes not registered, the logs show a successful
isElementPresent link=myLink
click link=myLink
but the browser doesn't react. These are mainly in-page links which open a new folder or an editing box.
I'm not sure whether I should have posted the in three separate questions, but I didn't want to spam.
Hope someone can help me, as I have these problems now for nearly 3 weeks.
Thanks in advance
Thomas
For your question number 2: Okay, this is a really late reply. I stumbled on this page looking for the answer myself. Given that I have solved it in the meantime, I figured I'd post my answer for other people stumbling onto this page.
General solution:
You need to create or use a profile that will let firefox automatically forward your credentials to the sharepoint website. You can create the profile manually and call it each time, see https://applicationtestingtips.wordpress.com/2009/12/21/seleniumrc-handle-windows-authentication-firefox/ for instructions.
Programmer solution: (works in python, should work similarly in Java)
Or you can create a new profile on the fly each time. I did that based on the information in the previously mentioned website. I use python for calling selenium, but this should be rather similar in whatever language you use to call selenium:
sharepointHosts = 'sharepoint1.mycompany.com,sharepoint2.mycompany.com' #have all your sharepoint hosts here in a comma-separated list
ffProfile.set_preference('network.automatic-ntlm-auth.trusted-uris', sharepointHosts)
ffProfile.set_preference('network.negotiate-auth.delegation-uris', sharepointHosts)
ffProfile.set_preference('network.negotiate-auth.trusted-uris', sharepointHosts)
driver = webdriver.Firefox(firefox_profile=ffProfile)
One of our most common error situations in a web application is that a user executes a GET request where the form should have submitted a POST.
I realize that the most likely case is that they got to the page (by way of a POST) and then clicked in the address bar and hit enter.
The question is, are there other less obvious ways that this could happen (print previews/back button, etc)?
We have never been able to consistently repeat the problems. The problems for different users and different pages nor do they happen very often (maybe once a week).
EDIT:
There is no data submitted with the GET request and therefore the processing page crashes out.
I was having a similar issue, although it doesn't sound like this was exactly yours. I had a form that was being submitted via ajax and shouldn't ever use the default submit. Now and then I was receiving errors from a GET done on the form. It shouldn't be possible to submit this form; however, certain versions of Safari for Mac were submitting it on enter. I just added a jquery form.submit() catch on it to prevent the default functionality. I also set the action to a page that wouldn't result in error (in case of lack of javascript).
As you said your problem is intermittent, so having a problem in form method set as get instead of post can be overruled but yes you are right, that if user presses enter in address bar it would be a get request and back button request always depends upon the last request made, if it was a post then any good browser will prompt you about resubmission and if it was get then no prompt, page will be bought back(may be from cache).
May be you can use Firebug (track requests in .net tab)or Fiddler and do some tests with different users/pages if you can reproduce it, its simply pressing enter in address bar.
Edit:
And also get is always supposed to 'retrieve information' so if browser is missing something or need something it will be a get but again check in IIS log for those get requests and try them in browser,if they contains query string for viewstate and eventvalidation, then they are really mis-formed request from post to get, if form method is not explicitly set to get.
I believe that an answer to the question "what are reasons for a browser executing GET rather than POST" does not help to solve the problem of receiving a GET on a form where you expect the a GET. But: To answer that question I would simply say that you receive an GET because the browser sends an GET and you can send a GET on any page where you can send a POST. On the other hand, if the user uses the form the browser sends a POST. Thus your server has to be prepared to handle the GET and it should handle the GET in the same manner as a POST with invalid parameters. My suggestion:
If you receive a GET, display the form again.
If you receive a POST with invalid data, display the form again and notify the user that he has to enter the data in a specific way.
Maybe a trivial answer, but that's what I would do. Don't know if it adds to the discussion.
Wrong, the most obvious reason why you get a GET instead of a POST is that because you're doing a GET instead of a POST.
A less obvious reason is you forgot to specify method="post" in one of your forms. The HTML standard specifies that the default method is GET, so if you want to POST, you must specify method="post" explicitly.
Scrutinize all of your tags and make sure all of them explicitly specify method="post".
EDIT: When you click on the address bar and pressed enter, yes it's true that the browser will GET a page, but your form wouldn't be submitted that way since the browser treats the URL similar to how a copy-pasted URL would be: a new session without any additional information sent to the server (except cookies).