1

I've got an application which takes advantage of a number of features of the Twitter API. I've tested the application on one Windows 7 system, and all features worked well.

Testing the application on a second Windows 7 system, it seems that everything but the Public Stream and User Stream features is working (i.e. the app managed to authenticate, can follow/unfollow users, etc). On this system, the Stream features produce a 401 error. As I understand it, 401 could indicate an authorization error (which isn't happening in this case, since non-streaming features are available), or a difference in time configuration between Twitter's servers, and the client system.

I'd like the streaming features of my app to be available cross platform (Windows, Mac, Unix), and I can't expect end-users to tinker with their system's clock configurations. Can anyone recommend a system-agnostic Tweepy/python-based solution to the 401 error issue under the condition that it's caused by a time-configuration problem? Thanks.

EDIT:

On the system on which the Stream features were not working, after having manually tinkered with the system clock, with no success, I synchronized with time.windows.com. This didn't have any discernible effect on the time that was showing (I didn't have a view of the seconds), but it resolved the problem (i.e. the Twitter User and Public Stream features became available). The question remains - how does one prevent such an error from arising on end users' systems? It's unrealistic for me to warn users to adjust their clocks.

Boa
  • 2,609
  • 1
  • 23
  • 38
  • Are you sure it's not authentication error? Just going off of the API docs [Streaming With Tweepy](http://docs.tweepy.org/en/v3.4.0/streaming_how_to.html): `API authorization is required to access Twitter streams.` – chickity china chinese chicken Sep 29 '16 at 00:34
  • @downshift If it were an authentication error, I don't believe that I would be able to use all of the non-streaming functionality, as the streaming and non-streaming functions use the same set of credentials. Also, it wouldn't explain why the program works on one machine, and not on another. – Boa Sep 29 '16 at 02:54
  • I am sure you are right about the authentication requirements, you have better understanding and experience than I using the api. Yet the program could work on one system that has environment variables set for the credentials and none set on the other computer, which was why I asked, but fair enough, you've corrected me. – chickity china chinese chicken Sep 29 '16 at 03:22

1 Answers1

1

Your system clock is probably more than 5 minutes off.

Jonas
  • 3,969
  • 2
  • 25
  • 30
  • Oddly enough, the clock on the Windows 7 machine on which it wasn't working was showing basically the same time (maybe a couple of seconds off) as the Win 7 machine on which it was working. But the question had to do with implementing a multi-system tweepy/python-based solution to the clock issue. Any suggestions on that? – Boa Sep 29 '16 at 02:50
  • You can get away with up to 3 simultaneous streams opened with the same credentials. Were you able to get the second instance working while the first instance was stopped? – Jonas Sep 29 '16 at 14:43
  • it turned out to be a clock issue, and after unsuccessful manual clock adjustments, synchronizing with Microsoft's time server fixed it. But the question is, how to prevent this issue from arising across end-users' systems, without asking them to adjust their clocks? – Boa Sep 29 '16 at 16:06
  • That's what an NTP server is for. Users don't have to manually adjust their clock anymore. They can point their system clock to an internet time server. Give the users instructions like [this](http://www.guidingtech.com/3119/windows-clock-sync/). – Jonas Sep 29 '16 at 17:15
  • Thanks, Jonas - I'd like to explore options that wouldn't burden the user with having to adjust the system clock or play with any system settings (i.e. perhaps the functionality of the Twitter API that requires the user system's time can instead be provided, by the program, with a time obtained from the NTP server). If it turns out that the only option is to force the user to adjust/sync the system clock, I'll go with that, but I think that this should be the last resort. – Boa Sep 29 '16 at 17:44
  • You could set the HTTP timestamp yourself, but you would still need to get the correct time from somewhere. – Jonas Sep 29 '16 at 18:31
  • Obtaining a time that works with the Twitter API can be done in the following way (allowing for the specification of a different server, if necessary): https://stackoverflow.com/questions/12664295/ntp-client-in-python. How do you set the HTTP timestamp yourself within the context of Tweepy's streaming functionality? – Boa Sep 29 '16 at 18:48