Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP request failed! HTTP/1.0 426 Upgrade Required #86

Open
eduardoblucas opened this issue Jan 21, 2021 · 5 comments
Open

HTTP request failed! HTTP/1.0 426 Upgrade Required #86

eduardoblucas opened this issue Jan 21, 2021 · 5 comments

Comments

@eduardoblucas
Copy link

Hi, I'm getting this error now. Any ideas? thanks

ErrorException: gzfile(https://ton.twimg.com/advertiser-api-async-analytics/slKanmA6oZyP8UlbYrjfkN6tbke2ZMQVFp_d1sWiQWKfpLiGd4AuannFvvEFS0Kv7s55-2n4sl7q7aawZy2kW7o6ZQ-jMp_PrA_7I9Lyx_UiuuiFSAlbfZwJbufS7RAg.json.gz): failed to open stream: HTTP request failed! HTTP/1.0 426 Upgrade Required

@theorytank
Copy link

theorytank commented Jan 27, 2021

I was having the same issue when requesting the payload from a async job. The response from $job->getUrl() returns a URL that you are probably passing directly to the gzfile() function. I've noticed that there's a timing issue (on the Twitter side) that the GZ'd payload at the getUrl() location isn't ready. So, on failure, if you sleep for a second and try again (a few times) eventually the payload returns.

Rough example of a solution:

                    $job->read();

                    if ($job->getStatus() == JobFields::SUCCESS) {

                         $cnt = 5; // 5 attempts before abandoning
                        $result = false;

                        while($cnt--) {
                            $result = @gzfile($job->getUrl());
                            if( !$result ) {
                                sleep(1);
                            } else {
                                break; // Leave while loop because we have a result
                            }
                        }

                        if( $result ) {
                            // Do your processing here.
                        }
                    }

@hborras
Copy link
Owner

hborras commented Jan 27, 2021 via email

@hborras
Copy link
Owner

hborras commented Feb 7, 2021

Checked it and it's working:

This is the test code I'm using:

`$job = $lineItem->stats(
[
TwitterAds\Fields\AnalyticsFields::METRIC_GROUPS_BILLING,
TwitterAds\Fields\AnalyticsFields::METRIC_GROUPS_MOBILE_CONVERSION,
TwitterAds\Fields\AnalyticsFields::METRIC_GROUPS_ENGAGEMENT,
],
[
TwitterAds\Fields\AnalyticsFields::START_TIME => $date[0],
AnalyticsFields::END_TIME => $date[1],
AnalyticsFields::GRANULARITY => Enumerations::GRANULARITY_TOTAL,
AnalyticsFields::PLACEMENT => Enumerations::PLACEMENT_ALL_ON_TWITTER
], $async
);
while($job->getStatus() == TwitterAds\Fields\JobFields::PROCESSING){
echo 'Job is still processing. Waiting 5 more seconds' .PHP_EOL;
$job->read();
sleep(5);
}

            if($job->getStatus() == TwitterAds\Fields\JobFields::SUCCESS){
                $result = gzfile($job->getUrl());
                $result = implode('', $result);
                $stats = json_decode($result)->data;
                $stats = $stats[0]->id_data[0]->metrics;
                if (!is_null($stats->billed_charge_local_micro)) {
                    echo "\t\t\t Start: " . $date[0]->format('Y-m-d H:i:s') . PHP_EOL;
                    echo "\t\t\t End: " . $date[1]->format('Y-m-d H:i:s') . PHP_EOL;
                    echo "\t\t\t " . ($stats->billed_charge_local_micro[0] / 1000000) . '€' . PHP_EOL;
                    echo "\t\t\t\t App clicks: ";
                    getStats($stats->app_clicks);
                    echo "\t\t\t\t Installs:" . PHP_EOL;
                    getStats($stats->mobile_conversion_installs);
                    echo "\t\t\t\t Checkouts:" . PHP_EOL;
                    getStats($stats->mobile_conversion_checkouts_initiated);
                }
            }`

@eduardoblucas
Copy link
Author

Hi any idea why this happens sometimes?

It is happening again and I didn't change anything.

ErrorException: gzfile(https://ton.twimg.com/advertiser-api-async-analytics/tOMs85xJqNl4ZqFzCkGYyYFmgwirELTozxz3Vkw7I8cPeVZnyDgcusfLPs9E9IPJmM_v6SqK07vsXuu-8Ko5_gfG8XmkI_sphweYDLBrjzr43raU9D1GhtXjS_21p_0L.json.gz): failed to open stream: HTTP request failed! HTTP/1.0 426 Upgrade Required

@hborras
Copy link
Owner

hborras commented Mar 2, 2021

Hi @eduardoblucas

If it happens "somentimes" it could be an error on Twitter's side, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants